首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何指定用道奇位置绘制的条形组的顺序

如何指定用道奇位置绘制的条形组的顺序
EN

Stack Overflow用户
提问于 2020-03-19 18:36:04
回答 1查看 346关注 0票数 4

我在Ordering position "dodge" in ggplot2有一个关于这个问题的问题。我不指定每个酒吧组中各个酒吧的顺序,例如在下面的地块(从上面的链接中)右边放置认证的位置,而是指定酒吧组的顺序,例如将Soziale Madien放在左边。下面的代码可以在上面的链接中找到,并在这里与我任意创建的数据重复,这样您就可以尝试生成类似的图了。

代码语言:javascript
复制
library(ggplot2)

AllCoursesReg <- data.frame(name=c( 'a', 'b', 'c', 'd', 'e','a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e','a', 'b', 'c', 'd', 'e'), Course=c('Gratis Online Lernen 2014', 'Soziale Medien', 'Soziale Medien', 'Gratis Online Lernen 2014', 'Lernen im Netz', 'Soziale Medien', 'Lernen im Netz', 'Gratis Online Lernen 2014', 'Lernen im Netz', 'Soziale Medien', 'Gratis Online Lernen 2014', 'Lernen im Netz', 'Soziale Medien', 'Gratis Online Lernen 2014', 'Lernen im Netz', 'Soziale Medien', 'Lernen im Netz', 'Gratis Online Lernen 2014', 'Lernen im Netz', 'Soziale Medien'), Status=c('Registrants','Certified', 'Registrants','Certified', 'Certified', 'Registrants','Certified', 'Registrants',  'Registrants','Registrants', 'Certified', 'Registrants','Certified', 'Registrants','Certified', 'Certified','Certified', 'Registrants',  'Certified','Certified'))

ggplot(AllCoursesReg, aes(Course, fill = Status)) +
geom_bar(aes(order = Status), position = "dodge", colour = "black") + theme_bw()+
guides(fill = guide_legend(reverse = TRUE))

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-19 23:30:54

您可以指定xlimits:

代码语言:javascript
复制
desired = c('Soziale Medien', 'Lernen im Netz', 'Gratis Online Lernen 2014')

ggplot(AllCoursesReg, aes(Course, fill = Status)) +
geom_bar(position = "dodge", colour = "black") + 
theme_bw()+
scale_x_discrete(limits=desired)+
guides(fill = guide_legend(reverse = TRUE))

或者改变因素的水平:

代码语言:javascript
复制
AllCoursesReg$Course = factor(AllCoursesReg$Course,levels=desired)

ggplot(AllCoursesReg, aes(Course, fill = Status)) +
geom_bar(position = "dodge", colour = "black") + 
theme_bw()+
guides(fill = guide_legend(reverse = TRUE))

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60763182

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档