[英]Ordering position “dodge” in ggplot2
似乎很簡單,但我找不到解決方案。
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))
我只希望注冊人位於左側而不是右側。 我已經嘗試過訂單,水平,因素,但它不起作用
謝謝你的幫助。
您必須決定一個factor
的水平順序。 這是來自?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
自從這個問題以來,ggplot已經更新,所以這是一個利用ggplot2的新功能的答案。
只需將position_dodge2(reverse = TRUE)添加到position屬性。 使用OP的代碼:
ggplot(AllCoursesReg, aes(Course, fill = Status)) +
geom_bar(aes(order = Status), position=position_dodge2(reverse = TRUE), colour = "black") + theme_bw()+
guides(fill = guide_legend(reverse = TRUE))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.