R plot filled.contour()输出在ggpplot2中

R plot filled.contour()输出在ggpplot2中,r,ggplot2,contour,graphing,R,Ggplot2,Contour,Graphing,我想绘制这个用filled.contour()创建的图形,但在ggplot2中,我该如何绘制 我想使用ggplot2,因为绘图约定更容易。我之所以要使用filled.contour()是因为我尝试了geom_tile()和image.plot(),它们都创建了非常类似于tile的输出,我需要一个类似filled.contour()的输出 这是我的数字: 代码: 库(akima) df我从 #生成数据 库(重塑2)#用于熔化 火山3D您可以根据需要调整颜色: gdat <- interp2

我想绘制这个用filled.contour()创建的图形,但在ggplot2中,我该如何绘制

我想使用ggplot2,因为绘图约定更容易。我之所以要使用filled.contour()是因为我尝试了geom_tile()和image.plot(),它们都创建了非常类似于tile的输出,我需要一个类似filled.contour()的输出

这是我的数字:

代码:

库(akima)

df我从

#生成数据
库(重塑2)#用于熔化

火山3D您可以根据需要调整颜色:

gdat <- interp2xyz(fld, data.frame=TRUE)

ggplot(gdat) + 
  aes(x = x, y = y, z = z, fill = z) + 
  geom_tile() + 
  coord_equal() +
  geom_contour(color = "white", alpha = 0.5) + 
  scale_fill_distiller(palette="Spectral", na.value="white") + 
  theme_bw()

注意:在一个像样的桌面系统上,这将持续几秒钟。在我相当强壮的MacBook Pro上:

   user  system elapsed 
  6.931   0.655   8.153 

要继续@hrbrmstr的最小示例,还可以使用ggplot2计算“z”:


您的数据片段包含重复项并导致
interp
问题。还有,你为什么要附加
df
?我可能会以某种方式消除重复项,但至于附加,只是因为有人告诉我要这样做。所以我不应该?那么你找到用ggplot模拟填充轮廓的方法了吗?谢谢,但正如我在问题中所说的,我以前试过geom_tile,然后又试过你的代码,但它太像素化了。有没有办法减少像素化?Chearshi@hbrmstr回答得很好,但我还有一个问题。可以在插值场上添加几何路径吗?我不会成功的。
fld <- with(df, interp(x = longitude, 
                       y = latitude, 
                       z = d13C,
                       xo = seq(min(longitude), max(longitude), length=400),
                       duplicate="mean"))
ggplot(gdat) + 
  aes(x = x, y = y, z = z) + 
  geom_tile(aes(fill=z)) + 
  coord_equal() +
  stat_contour(aes(fill=..level..), geom="polygon", binwidth=0.005) + 
  geom_contour(color="white", alpha=0.5) +
  scale_fill_distiller(palette="Spectral", na.value="white") + 
  theme_bw()
   user  system elapsed 
  6.931   0.655   8.153 
library(ggplot2)
ggplot(data = faithful, aes(x = eruptions, y = waiting)) +
  stat_density2d(aes(colour = ..level.., fill = ..level..), geom = "polygon")