有人可以帮助我了解如何在ggplot2中使用stat_summary在条形图上方稍微放置均值标签吗?这是我的代码:
#Create data frame
industry = c(1,1,1,1,1,2,2,2,2,2)
choice = c(1,2,3,2,1,4,5,3,5,5)
df =data.frame(industry,choice)
#Define data to plot
line <- ggplot(df, aes(industry, choice))
#Plot data, bar chart
test <- line +
theme_classic() +
stat_summary(fun.y = mean, geom = "bar", width=0.4, aes(group = 1)) +
labs(x = "product", y = "firm size preference") +
scale_x_discrete(limits=c("pizza","headphones")) +
theme(text = element_text(size=12))
test +
ggtitle(label = "FIGURE 1", subtitle = "FIRM SIZE PREFERENCE") +
theme(
plot.title = element_text(hjust = 0.5, size = 12),
plot.subtitle = element_text(hjust = 0.5, size = 10)
)