【发布时间】:2017-11-15 15:32:23
【问题描述】:
我有一个包含三个变量的数据框:位置、天气和厕所。
我想在 ggplot2() 中使用 geom_tile 制作热图,这样天气在 y 轴上,位置在 x 轴上,wc 是填充。我在https://learnr.wordpress.com/2010/01/26/ggplot2-quick-heatmap-plotting/ 上找到了一些代码,产生了我正在寻找的那种情节。
问题在于,虽然我可以制作基本情节 (p),但我无法获得最后润色的代码(网页上有最终产品的视觉效果)。据我所知,其中一些代码适用于旧版本的 ggplot2(),但我无法弄清楚更新后的等价物是什么。
任何帮助将不胜感激。
起点(df):
df1 <- data.frame(location=c("az","az","az","bi","bi","ca","ca","ca"),weather=c(1,2,3,2,3,1,2,3),wc=c(2,1,1,2,1,2,2,1))
当前代码:
p <- ggplot(df1, aes(location,weather)) + geom_tile(aes(fill = wc),colour = "white") +
scale_fill_gradient(low = "white", high = "steelblue")
p + theme_grey(base_size = base_size) + labs(x = "", y = "") +
scale_x_discrete(expand = c(0, 0)) + scale_y_discrete(expand = c(0, 0)) +
opts(legend.position = "none", axis.ticks = theme_blank(), axis.text.x = theme_text(size = base_size * 0.8, angle = 330, hjust = 0, colour = "grey50"))
【问题讨论】: