X、Y 和 Z 数据集使用geom_tile
. 我想在值小于或等于 2 的图块周围画一条等高线。为此,我使用了该stat_contour
函数,但结果不如预期。我怎样才能得到预期的结果?(最后一张图片)
library(ggplot2)
X <- 1:3
Y <- seq(0,20,10)
df <- expand.grid(X = X, Y = Y)
df$Z <- c(5,4,9,2.1,1.5,1.2,6,7,1.9)
ggplot(df, aes(X, Y)) +
geom_tile(aes(fill = Z)) +
scale_fill_distiller(palette = "RdYlGn") +
stat_contour(aes(z = Z),
breaks = 2,
color = 1)
我想要类似的东西: