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

谢谢。
发布于 2020-03-19 23:30:54
您可以指定xlimits:
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))或者改变因素的水平:
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))

https://stackoverflow.com/questions/60763182
复制相似问题