我是R的新手,我想绘制一张污染物分布/轮廓的地图,我很难做到这一点。
我的数据集示例是:
> head(noxco2_contour)
latitude longitude NOX.CO2
1 52.45060 -1.933200 0.01240829
2 52.45061 -1.933198 0.01045806
3 52.45060 -1.933207 0.01235869
4 52.45059 -1.933202 0.01083601
5 52.45059 -1.933199 0.01243808
6 52.45058 -1.933207 0.01379813
在使用ggmap获取所需的地图后,我试图覆盖NOX.CO2的填充轮廓。我正在使用此代码:
`ggmap(west_midlands, extent = "panel") + geom_density2d(data = noxco2_contour, aes(x = longitude, y = latitude, z=NOX.CO2), size = 0.3, contour=T) +
stat_density2d(data = noxco2_contour,
aes(x = longitude, y = latitude, z= NOX.CO2, fill = ..level.., alpha = ..level..), size = 0.05,
geom = "polygon") + scale_fill_gradient(low = "green", high = "red") +
scale_alpha(range = c(0, 1), guide = FALSE)
但是我收到的警告信息是:'警告:忽略未知的美学:z'实际上,填充不是NOX.CO2的实际值,而是未知值/物质的水平。我得到的图像是1,这是不正确的。
我检查了以下相关链接Filled contour plot with R/ggplot/ggmap 3,但我得到了不同的错误,但仍然没有正确的填充。 使用时:
ggmap(west_midlands, extent = "panel") + geom_density2d(data = noxco2_contour, aes(x = longitude, y = latitude), size = 0.3) +
+ stat_density2d(data = noxco2_contour,
+ aes(x = longitude, y = latitude, group= NOX.CO2, colour= NOX.CO2), size = 0.05,
+ geom = "polygon") + scale_fill_gradient(low = "green", high = "red") +
+ scale_alpha(range = c(0, 1), guide = FALSE)
我得到以下内容:stat_density2d()
中的计算失败:
缺少需要TRUE / FALSE的值
当我使用此代码时
`ggmap( west_midlands, extent = "panel" ) +
+ stat_contour(data = noxco2_contour, geom="contour", bins=20,
+ aes(x = longitude, y = latitude, z = NOX.CO2, fill = ..level.. ) ) +
+ scale_fill_continuous(name = "NOx(ppb)/CO2(ppm)", low = "yellow", high = "red" )
我收到此Computation failed in
stat_contour():
Contour requires single
z at each combination of
x and
y`。
我非常感谢任何帮助
非常感谢, 比尔