r - stat_summary 条形图标签
问题描述
有人可以帮我理解如何在 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)
)
解决方案
推荐阅读
- sql - 是否可以将分组的行汇总到另一列,但只显示其中 1 行的总和结果?
- javascript - 在数据库中查找不成功后,如何用已插入的文本替换表单?
- c - C中颜色的数据类型,我想要双精度/浮点精度,但数字在0-255范围内
- neo4j - 导入本地 CSV 文件时 neo4j-import 失败
- java - 在“Modisco”Java 模型上运行“EMF 重构”重构的问题
- scala - cassandra 长时间运行的查询分页
- google-apps-script - 创建一个循环遍历所有工作表的宏
- c# - 如何从泛型类型中找出数据的类型
- pbs - PBS Pro:由用户设置作业数组插槽限制
- c++ - Clion:Gtest TEST_F 不适用于 std::cin