我是ggplot2的新手,我正在尝试复制我使用filled.contourggplot2 创建的图形.
下面是我的代码:
require(ggplot2)
require(reshape2)
#data prep
scale <- 10
xs <- scale * c(0, 0.5, 0.8, 0.9, 0.95, 0.99, 1)
ys <- scale * c(0, 0.01, 0.05, 0.1, 0.2, 0.5, 1)
df <- data.frame(expand.grid(xs,ys))
colnames(df) <- c('x','y')
df$z <- ((scale-df$x) * df$y) / ((scale-df$x) * df$y + 1)
#filled contour looks good
filled.contour(xs, ys, acast(df, x~y, value.var='z'))
#ggplot contour looks bad
p <- ggplot(df, aes(x=x, y=y, z=z))
p + stat_contour(geom='polygon', aes(fill=..level..))
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何让ggplot轮廓一直填充到左上角的多边形(在(0,10)处有一个点,z = 0.99)...我得到的是这些奇怪的三角形