geom_text制作标签出现在图中
我正在尝试使我的dataFrame的列“Activitéen valeur”的值出现在我的geom_bar中的栏上方,但由于我收到以下错误消息,它不起作用。数据(11):标签”。我该如何修复?
library(ggplot2)
ggplot() +
geom_bar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
标签上添加标签映射
审美<代码> aes(),而不是将数据帧列作为参数。另外,由于您有一个躲闪的栏,因此还必须将标签的位置设置为position_dodge()
,在这里您必须设置道奇的宽度,默认情况下,该宽度为.9 forgeom_bar/col
。我还将您的值四舍五入为一个数字,并通过设置vjust = - 。1
稍微移动它们。最后,作为一般提醒,请勿使用fra_acti_valeur_par_type $ ...
在ggplot2中。只需在Aesthetics上映射列名:To add your labels map on the
label
aesthetic insideaes()
instead of passing dataframe column as argument. Also, as you have a dodged bar you have to set the position for the labels toposition_dodge()
as well, where you have to set the width of the dodge which by defaults to .9 forgeom_bar/col
. I also rounded your values to one digit and moved them slightly by settingvjust=-.1
. Finally, as a general reminder, don't usefra_acti_valeur_par_type$...
in ggplot2. Simply map the column name on aesthetics:您在
geom_text
美学中使用group
的另一个选项,因此它知道要躲闪的值:output:
Another option where you use
group
in yourgeom_text
aesthetics, so it knows which values to dodge:Output: