【发布时间】:2017-11-07 11:33:43
【问题描述】:
我正在尝试创建一个像 here 这样的发散堆叠条,并且遇到了与此 SO question 类似的问题。我的方法略有不同,因为我通过一个数据集而不是两个数据集进行管理,而且我的颜色与我的数据无关。
表示如下:
library(tidyverse)
library(RColorBrewer)
x <- tribble(
~response, ~count,
0, -27,
1, -9,
2, -41,
3, -43,
4, -58,
5, -120,
5, 120,
6, 233,
7, 379,
8, 388,
9, 145,
10, 61
) %>%
mutate(response = factor(response))
ggplot(x, aes(x = 1, y = count, fill = response)) +
geom_col() +
scale_fill_brewer(palette = "RdBu") +
coord_flip()
问题在于堆叠数据在零的右侧的排序,在那里它们堆叠似乎是按降序排列的。任何关于如何解决此问题的想法将不胜感激(预期的排序将是 0-10,而不是 0-5,10-5)
【问题讨论】: