大佬教程收集整理的这篇文章主要介绍了ggplot的饼图geom_text()标签隐藏了由geom_bar()制作的饼图,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
structure(list(Group.1 = structure(c(1L,2L,3L,1L,3L),.Label = c("Black or African American","White Alone","White Alone LR"),class = "factor"),Group.2 = structure(c(1L,.Label = c("bus","mixed","rail" ),x = c(75143.5182835844,198737.537113379,46973.6469041183,46199.2335265697,128026.568239224,28933.3028730992,75876.5845180076,495166.957025367,5909.04640985574),pos = c(37571.7591417922,99368.7685566897,23486.8234520592,98243.1350468693,262750.821232991,61440.2983406679,159281.044069158,574347.583865287,78861.4729821454 ),labe = c(" 75,144","198,738"," 46,974",199","128,027"," 28,933"," 75,877","495,167"," 5,909")),class = c("tbl_df","tbl","data.frame"),.Names = c("Group.1","Group.2","x","pos","labe"),row.names = c(NA,-9L))
我得到了一个很好的代码来制作饼图here和here,这导致了这个:
@H_842_2@modesplit <- ggplot(data = sums) + geom_bar( aes(factor(1),y=x,fill=Group.2),stat="identity",position="fill") + scale_fill_discrete(guide=guide_legend(title="Mode")) + coord_polar(theta="y") + faCET_grid(.~Group.1,labeller = label_value) + scale_x_discrete(name=" ",breaks = NULL) + scale_y_conTinuous(name=" ",breaks = NULL) plot(modesplit)但是,当我尝试添加标签时:
@H_842_2@modesplit <- ggplot(data = sums) + geom_bar( aes(factor(1),position="fill") + geom_text(aes(,y=pos,label = labE),size =5) + scale_fill_discrete(guide=guide_legend(title="Mode")) + coord_polar(theta="y") + faCET_grid(.~Group.1,labeller = label_value) + scale_x_discrete(name=" ",breaks = NULL) + plot(modesplit)饼图的“馅饼”消失了:
我试过了:
>移除秤
>删除scale_fill_discrete
这是一个解决方案(编辑所以它现在很好地将标签放在中间)
library(dplyr) sums2 = sums %>% group_by(Group.1) %>% mutate(x_scaled = x / sum(X),pos_scaled = pos / cumsum(x_scaled) - x_scaled / 2) modesplit <- ggplot(data = sums2,aes(x = factor(1))) + geom_bar( aes(y=x_scaled,position="stack") + scale_fill_discrete(guide=guide_legend(title="Mode")) + coord_polar(theta="y") + geom_text(aes(y = pos_scaled,size =5) + faCET_grid(. ~ Group.1,breaks = NULL) plot(modesplit)
以上是大佬教程为你收集整理的ggplot的饼图geom_text()标签隐藏了由geom_bar()制作的饼图全部内容,希望文章能够帮你解决ggplot的饼图geom_text()标签隐藏了由geom_bar()制作的饼图所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。