【发布时间】:2019-12-02 21:16:39
【问题描述】:
我正在尝试将条形图重新排序为降序(联系率最高的道路组位于顶部)。但是 reorder() 函数似乎不起作用。
for (i in uniq_wards)
{ print(ggplot(data = subset(roads, Ward == i),
aes(x = reorder(Roadgroup, Contact.rate),
y = Contact.rate,
fill = undecided_rate)) +
geom_col() +
coord_flip() +
labs(fill = "Undecided rate", y = "Contact Rate", x = "Road Group") +
theme(axis.text.x = element_text(angle = 90),
text = element_text(size = 8)) +
scale_fill_gradient(low = "gray", high = "blue", limits=c(0.0, 0.35)) +
ggtitle(i, subtitle = "Contact Rate and Undecided Density"))
}
第二个图像是我希望第一个图看起来像的降序示例,它使用相同的变量轴 reorder() 代码:
x = reorder(Roadgroup, Contact.rate),
y = Contact.rate,
【问题讨论】:
-
欢迎来到 SO。请阅读how to ask a good question。你更有可能得到答案