r - ggplot2 中的平均值
问题描述
我目前正在做一个项目,我想在图表中找到平均值。
这是我写的 ggplot2 的代码
ggplot(data = estates, aes(x=town, y=resale_price , fill=town)) +
geom_bar(stat='identity',position = 'dodge') +
ggtitle("Resale Price based on estate")+xlab("Town")+ylab("Resale price")+
theme(plot.title = element_text(color = "red",size = 10,face = "bold.italic",hjust = 0.5),
axis.title.x = element_text(color = "red",size = 8.5,face = "bold"),
axis.title.y = element_text(color = "red",size = 8.5,face = "bold")
)
我在哪里放置平均函数以便它显示在条形图上?
非常感谢
解决方案
此处发布了类似的答案:
像这样得到你的手段:
mu <- aggregate(resale_price ~ town, estates, mean)
然后将文本添加到ggplot
+ geom_text()
推荐阅读
- arrays - 如何将数组值附加到laravel中的集合中?
- android - 是否还有任何受支持的 Eclipse 应用程序\版本?(用于维护旧项目)
- ios - TrueDepth 相机前景分割,改善遮罩效果
- json - 将 JSON 文件转换为 TFRecord 时出现错误
- ruby-on-rails - 在使用 minimagick 创建的 Ruby 中编辑 PDF 的元数据
- wordpress - 搜索查询的分页格式不正确 WP
- php - 与支付网关联系时延迟 PHP 代码一段时间
- node.js - 无法在 Strapi 项目中添加项目
- javascript - 用于显示和隐藏 html div 的 javaScript 函数不起作用
- python - 我需要显示所有可能的原始价格和最终价格