【发布时间】:2015-02-12 05:14:30
【问题描述】:
我正在寻找完全填充 ggplot2 的 stat_contour 生成的轮廓的方法。目前的结果是这样的:
# Generate data
library(ggplot2)
library(reshape2) # for melt
volcano3d <- melt(volcano)
names(volcano3d) <- c("x", "y", "z")
v <- ggplot(volcano3d, aes(x, y, z = z))
v + stat_contour(geom="polygon", aes(fill=..level..))
如下手动修改代码即可产生想要的结果。
v + stat_contour(geom="polygon", aes(fill=..level..)) +
theme(panel.grid=element_blank())+ # delete grid lines
scale_x_continuous(limits=c(min(volcano3d$x),max(volcano3d$x)), expand=c(0,0))+ # set x limits
scale_y_continuous(limits=c(min(volcano3d$y),max(volcano3d$y)), expand=c(0,0))+ # set y limits
theme(panel.background=element_rect(fill="#132B43")) # color background
我的问题:有没有办法在不手动指定颜色或使用geom_tile() 的情况下完全填充绘图?
【问题讨论】:
-
据我所知,您需要手动扩展数据集。您的解决方案看起来更简单,所以如果您对它感到满意,请保持原样。
-
我也看到了那个帖子,但是 geom_tile() 使用了小矩形,所以这不是我想要的效果。 fill.contour 迄今为止产生了最好的结果,但它与多重绘图的不兼容导致我尝试使用 ggplots。我想知道是什么产生了透明区域。
-
这里对您看到的工件进行了部分解释:stackoverflow.com/questions/23257951/…。看看您是否可以根据您的情况调整该答案?
-
成功了! @tonytonov 非常感谢!我将在下面发布答案。