订购位置“道奇"在ggplot2中 [英] Ordering position "dodge" in ggplot2
本文介绍了订购位置“道奇"在ggplot2中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
看起来很简单,但是我找不到解决方法.
Seems simple but i couldnt find a solution.
names(AllCoursesReg)
[1] "name" "Course" "Status"
我的代码
ggplot(AllCoursesReg, aes(Course, fill = Status)) +
geom_bar(aes(order = Status), position = "dodge", colour = "black") + theme_bw()+
guides(fill = guide_legend(reverse = TRUE))
我只希望注册人位于左侧而不是右侧. 我已经尝试过订单,水平,因素,但它不起作用
I just want the Registrants to be on the left not on the right. I have tried Order, level, factor, and it is not working
感谢您的帮助.
推荐答案
您必须确定factor
的级别顺序.这是来自?geom_bar
的示例.
You have to decide on the ordering of the levels of a factor
. Here's an example from ?geom_bar
.
# example from ?geom_bar
ggplot(diamonds, aes(clarity, fill=cut)) + geom_bar(position="dodge")
# reorder cut using levels = rev(levels(cut))
ggplot(diamonds, aes(clarity, fill=factor(cut, levels = rev(levels(cut))))) +
geom_bar(position="dodge") +
scale_fill_discrete('cut') # change name back to cut
这篇关于订购位置“道奇"在ggplot2中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文