使用ggplot2在facet躲避条形图上添加文本

概述我想在两年内制作一个躲避条形图,并将收入数字放在相应的栏上.在尝试了一些我在这里找到的建议之后,我仍然无法得到我想要的东西(所有数字都显示在中间条/列的中间而不是均匀分布).任何建议将不胜感激.谢谢! 我的最新尝试 # Disable scientific notationoptions("scipen" = 100, "digits" = 1)censusData <- structur 我想在两年内制作一个躲避的条形图,并将收入数字放在相应的栏上.在尝试了一些我在这里找到的建议之后,我仍然无法得到我想要的东西(所有数字都显示在中间条/列的中间而不是均匀分布).任何建议将不胜感激.谢谢!

我的最新尝试

# disable scIEntific notationoptions("scipen" = 100,"digits" = 1)censusData <- structure(List(Year = c(2012L,2007L,2012L,2007L                                      ),County = c("A","A","B","C","Sum","Sum"),variable = structure(c(1L,1L,2L,3L,3L),.Label = c("Total_Revenue","Crop_Revenue","livestock_Revenue"                                      ),class = "factor"),value = c(1645.51,1203.806,68.911,60.949,923.163,525.918,2637.584,1790.673,1069.497,787.459,47.157,38.735,825.050228,470.024,1941.704228,1296.218,576.013,416.347,21.754,22.214,98.112772,55.894,695.879772,494.455                                      )),row.names = c(NA,-24L),.names = c("Year","County","variable","value"),class = "data.frame")# Dodged barplotqbarplot_yr_1 <- ggplot(censusData,aes(County,value)) + facet_grID(. ~ Year) +    geom_bar(aes(fill = variable),position = "dodge",stat="IDentity") +  xlab("County") + ylab("Revenue (Million USD)") +  scale_fill_discrete(name = 'Legend',labels=c("Total","Crop","livestocks")) +  theme(axis.ticks.x = element_blank()) +  theme(panel.background = element_rect(colour='dark grey')) +  theme(strip.text.x = element_text(size = 20,face="bold"),strip.background = element_rect(colour="dark grey"))# Add text on top of the barqbarplot_yr_1 + geom_text(data = censusData,aes(x = County,y = value + 150,label = format(value,nsmall = 0,scIEntific = FALSE)),color="blue")
解决方法 您还需要躲避文本值.尝试
qbarplot_yr_1 + geom_text(data = censusData,group=variable,digits=1,color="blue",position=position_dodge(.9),hjust=.5)

我们还需要group =所以它知道要躲避哪些值.

总结

以上是内存溢出为你收集整理的使用ggplot2在facet躲避条形图上添加文本全部内容,希望文章能够帮你解决使用ggplot2在facet躲避条形图上添加文本所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1140979.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存