suppose I have the following barplot (the barplot can be created with the code)
set.seed(999)
similarity_context_set1 = matrix(rnorm(10*3,10,1),ncol=3)
similarity_context_set2 = matrix(rnorm(10*3,10,1),ncol=3)
attraction_prop_context_set1 = matrix(rnorm(10*3,10,1),ncol=3)
attraction_prop_context_set2 = matrix(rnorm(10*3,10,1),ncol=3)
compromise_context_set1 = matrix(rnorm(10*3,10,1),ncol=3)
compromise_context_set2 = matrix(rnorm(10*3,10,1),ncol=3)
library(tidyverse)
# add all matrices in a list. I use lst here since the ouptut is
# a named list
lst(similarity_context_set1,
similarity_context_set2,
attraction_prop_context_set2,
attraction_prop_context_set1,
compromise_context_set1,
compromise_context_set2) %>%
# transform to tibble and add column names
map(as_tibble) %>%
map(set_names, c("X", "Y","Third")) %>%
# bind the list to one dataframe, add list names to column by
# setting .id
bind_rows(.id = "name") %>%
# transform data from wide to long as it is recommended ggplot
#input format here
pivot_longer(-1,names_to = "x", values_to = "y") %>%
# make to columns for facetting
separate(name, into = c("name1", "name2"), sep = "_", extra = "merge") %>%
mutate(name2 = str_extract(name2, "[0-9]")) %>%
# finally the plot
ggplot(aes(x, y, group=x, fill = x)) + theme_hc(base_size = 13)+
geom_bar(stat = "summary", fun = "mean",alpha=0.8 )+
scale_fill_manual(values = c("Y" = "gray1","X" = "gray1","Third" = "gray1"), guide="none" )+
facet_grid(name2~name1)+
stat_summary(fun.data = mean_se, geom = "errorbar", width=0.2)+
ggtitle("Perceptual Domain")+
theme(plot.title = element_text(hjust = 0.5))+
labs(x = "Response", y = "Mean Choice Proportion")
How can I add an individual text above each bar? I don't want to write the average values above the bars, but a text like on the picture (Target, Competitor and Third) B
ild?
Do you know how I can additionally add different lines for each plot with labels? like this:

