更改堆叠条形图中的条形图顺序 [英] Changing the order of barchart in stacked bar
本文介绍了更改堆叠条形图中的条形图顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助我更改条形图的顺序.图例以正确的格式显示,但不知道为什么更改图表
Can anyone help me to change the order of bar graph . Here legend is showing in correct format but dont know why chart is changed
ggplot(x,aes(x=Total,y=Type,fill=status))+
geom_bar(stat='identity',width=0.2)+
theme_classic()+
#geom_text(aes(label = stat(x),group = Type),stat = "summary",fun = sum,vjust = .20,hjust= 1)+
theme(axis.line.y = element_blank(),axis.ticks = element_blank(),legend.position = "bottom",
axis.text.x = element_text(face = "bold", color = "black", size = 10, angle = 45, hjust = 1))+
labs(x="", y="", fill="")+
scale_fill_manual(values=c("#284a8d", "#00B5CE"))
解决方案
This is about as close as I could get it:
library(ggplot2)
ggplot(x,aes(x=Total,y=Type,fill=factor(status, c("Open", "Closed"))))+
geom_bar(stat='identity',width=0.2)+
geom_text(aes(label = after_stat(x)),
stat = "summary",fun.data = function(x){data.frame(y = sum(x))},
hjust= 0, position = position_stack(0))+
geom_text(aes(label = after_stat(x), group = Type),
stat = "summary",fun.data = function(x){data.frame(y = sum(x))},
hjust= 0, position = position_stack(1))+
labs(x="", y="", fill="")+
scale_fill_manual(values=c("#284a8d", "#00B5CE"),
limits = c("Closed", "Open")) +
theme_classic() +
theme(axis.line.y = element_blank(),
axis.ticks = element_blank(),
legend.position = "bottom",
axis.text.x = element_text(face = "bold", color = "black",
size = 10, angle = 45, hjust = 1))
这篇关于更改堆叠条形图中的条形图顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文