R 具有stat_等高线的曲面打印:缺少美学z

R 具有stat_等高线的曲面打印:缺少美学z,r,ggplot2,R,Ggplot2,我想用stat\u contour做一个曲面图。我有纬度(“x”)和长(“z”)信息以及一个连续变量,如高度。我的最终目标是像这样的情节 数据: x <-c(-21.035424, -21.120149, -21.059586, -21.092388, -20.992769, -21.013030, -21.125002, -21.147202, -21.122302, -21.072782, -21.040317, -21.117670, -21.121831,

我想用
stat\u contour
做一个曲面图。我有纬度(“x”)和长(“z”)信息以及一个连续变量,如高度。我的最终目标是像这样的情节

数据:

x <-c(-21.035424, -21.120149, -21.059586, -21.092388,
    -20.992769, -21.013030, -21.125002, -21.147202,
    -21.122302, -21.072782, -21.040317, -21.117670,
    -21.121831, -22.529201, -22.572593, -22.522127,
    -22.566072, -22.610095, -22.586590, -22.644440,
    -22.471389, -22.673909, -22.548114)
y <-c(-51.001460, -50.884732, -50.983601, -51.042580,
     -50.979595, -50.808481, -50.921407, -50.884710,
     -50.888586, -50.802156, -50.898742, -51.059770,
     -50.918690, -51.767669, -51.774862, -51.842172,
     -51.865384, -51.620441, -51.703657, -51.697475,
     -51.729553, -51.522697, -51.670556)
z <- c(71.42857,  57.14286, 14.28571,  28.57143,  71.42857,  57.14286,
   85.71429,  57.14286, 42.85714,  57.14286, 100.00000,  57.14286,
   85.71429,  71.42857, 57.14286,  57.14286,  28.57143,  28.57143,
   71.42857,  57.14286, 42.85714,  42.85714,  85.71429)

df <- data.frame(x, y, z)

如果我真的在geom_瓷砖中添加了“z”,为什么会缺少“z”。在
stat\u contour
文档中没有“z”aes。

最有效的方法如下:

g <- ggplot(df, aes(x=x, y=y, z=z))
g + stat_contour(geom='tile', aes(fill=..level..), binwidth=10)

g是否缺少一个括号?你采取了错误的原则。您可以看到它正在执行
df thanky You@PauloCardoso,但是在使用
expand.grid
“z”将添加到何处?z可能会像您所做的那样映射到ggplot(aes())。使用geom_tile,你的x和y应该形成一个耕作网格。@Thiagotoyosouza,如果我下面提供的建议回答了你的问题,你应该接受这个答案来结束这个问题。
Error: stat_contour requires the following missing aesthetics: z
g <- ggplot(df, aes(x=x, y=y, z=z))
g + stat_contour(geom='tile', aes(fill=..level..), binwidth=10)