r - R更改geom_bar()中文本的位置
问题描述
我想用geom_text()
. 每个条形图上方应该是变量的计数。但在这种情况下,文本的位置在条形图的中间。有人可以帮我解决这个问题吗?
new.data <- diamonds[ which( diamonds$clarity =="VS1" | diamonds$clarity =="VS2") , ]
ggplot(data=new.data, aes(x=clarity, fill=cut)) +
geom_bar(position = "dodge",stat = "count") +
geom_text(stat='count', aes(label=..count..), vjust=-1)
解决方案
在此处添加position
类似问题中提到的论点
new.data <- diamonds[ which( diamonds$clarity =="VS1" | diamonds$clarity =="VS2") , ]
ggplot(data=new.data, aes(x=clarity, fill=cut)) +
geom_bar(position = "dodge",stat = "count") +
geom_text(stat='count', aes(label=..count..), vjust=-1,
position = position_dodge(width = 0.9))
输出:
就像 TobKel 在评论中提到的那样,可以随宽度变化。
推荐阅读
- google-cloud-platform - 无法使用服务帐户订阅 google pub 子主题
- node.js - 找不到 Node.js 模块
- wso2 - WSO2 sh wso2server.sh -Dmigrate -Dcomponent=identity 没有运行迁移脚本
- r - 根据文件名列出文件
- android - 匿名类作为类成员
- d3.js - 如何在 topoJSON 网格上进行扭曲
- ios - UITableViewController 上的自定义弹出窗口是可滑动的 - 如何防止 - Swift
- mysql - MySQL:从结果中排除一些行?
- asp.net - 如何在 SQL Server 中创建在特定时间仅执行一次的触发器
- python - 如何在python3中的'\ + 234'字符串中提取'\ +'