【发布时间】:2020-08-30 05:40:46
【问题描述】:
ggplot 根据标签保留堆叠条的顺序:
d <- read.table(text='Day Location Length Amount
1 2 3 1
1 1 4 2
3 3 3 2
3 2 5 1',header=T)
d$Amount<-as.factor(d$Amount) # in real world is not numeric
ggplot(d, aes(x = Day, y = Length)) +
geom_bar(aes(fill = Amount), stat = "identity")
我想要的是与没有as.factor 线的情节类似的结果。那就是:更大的条总是在顶部。但是,我不能对我的数据执行此操作,因为我有类别,而不是数字。
类似帖子:https://www.researchgate.net/post/R_ggplot2_Reorder_stacked_plot
解决方案可以来自其他 R 包
注意:data.frame 只是示范性的。
【问题讨论】: