[英]How to order a heatmap in R by x or y?
I've created a heatmap on temperatures by city. 我已经根据城市创建了温度热图。 ggplot orders cities by default, from ZA, not what I want.
ggplot默认从ZA订购城市,而不是我想要的。 How can I change the code so that the cities would be ordered AZ, how overall x and y can be ordered in ggplot ?
如何更改代码以便对城市进行排序AZ,如何在ggplot中订购整体x和y?
ggplot(Cities, aes(x = Month, y = City, fill = AvgTemp, frame = City)) +
geom_tile(color = "white", size = 0.5) +
scale_fill_gradient(name = "Average Temperature",low = "blue", high = "red") +
coord_equal() +
labs(x = "Month", y = "", title = "Average Temp") +
theme_tufte() +
theme(axis.ticks = element_blank()) +
theme(axis.text = element_text(size = 15)) +
theme(plot.title = element_text(size = 15)) +
theme(legend.title = element_text(size = 10)) +
theme(legend.text = element_text(size = 10))
I've included a reorder
in your aes(y=)
. 我在你的
aes(y=)
包含了一个reorder
aes(y=)
。
ggplot(data=Cities) +
geom_tile( aes(x=Month, y=reorder(City, AvgTemp, median, order=TRUE), fill = AvgTemp), color = "white", size = 0.5) +
scale_fill_gradient(name = "Average Temperature",low = "blue", high = "red") +
coord_equal() +
labs(x = "Month", y = "", title = "Average Temp") +
theme_tufte()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.