你好,我有一个矩阵37x73,它表示一个变量(moavg),网格间距为10x10度(-180 < LON < 180和-90 < LAT < 90)。 我可以使用image绘制它。
image(LON, LAT, moavg)
但我无法显示颜色条。我想知道是否有另一种函数(也许是ggplot)可以做到这一点,还允许我绘制颜色图例。
非常感谢。
为了绘制格网化的空间数据,raster
和 rasterVis
包也很有用。
以下是几个例子:
library(rasterVis) # this will also load the raster package
# Create a raster from a matrix of dummy data
m <- matrix(runif(36*18), ncol=36)
r <- raster(m)
# Set the extent of the object
extent(r) <- c(-180, 180, -90, 90)
# plot with raster
plot(r)
# plot with rasterVis
levelplot(r, margin=FALSE)
library(maps)
levelplot(r, xlab='longitude', ylab='latitude', margin=FALSE,
panel = function(x, y, ...) {
panel.levelplot(x, y, ...)
mp <- map("world", plot = FALSE, fill=TRUE)
lpolygon(mp$x, mp$y)
})
?lattice::levelplot
中所述)。 - jbaums