在 R 的 levelplot 上叠加大陆轮廓
Overlay continent outlines on levelplot in R
我试图在图层图中重叠大陆轮廓,并希望用经度和纬度值标记 x 轴和 y 轴。目前我没有收到错误,但没有出现轮廓。我想知道这是否是因为我没有正确定义纬度和经度轴?
library(rgdal)
library(rasterVis)
library(RColorBrewer)
library(ncdf4)
library(maptools)
f<-nc_open("cases5.nc")
cases<-ncvar_get(f,"cholera_cases")
sen<-getData('GADM', country='Senegal', level=1)
colr <- colorRampPalette(brewer.pal(11, 'RdYlBu'))
for (i in seq(1,1)){
name<-sprintf("plot_%03d.png",i)
png(name)
print(name)
p<-levelplot(cases,
margin=FALSE, # suppress marginal graphics
colorkey=list(
space='bottom', # plot legend at bottom
labels=list(at=0:10, font=4) # legend ticks and labels
),
par.settings=list(
axis.line=list(col='transparent') # suppress axes and legend outline
),
scales=list(draw=FALSE), # suppress axis labels
col.regions=colr, # colour ramp
at=seq(0, 10, len=101))
+layer(sp.polygons(sen, fill="transparent"))
print(p)
dev.off()
}
此处提供了示例 netcdf 数据文件:
我认为你需要将一个 RasterLayer
对象传递给 levelplot:
library(rgdal)
library(rasterVis)
library(RColorBrewer)
library(ncdf4)
library(maptools)
library(raster)
r <- raster("/Users/christopher/Downloads/cases5.nc")
colr <- colorRampPalette(brewer.pal(11, 'RdYlBu'))
p <- levelplot(
r,
margin = FALSE,
colorkey = list(space = 'bottom',
labels = list(at = 0:10, font = 4)),
par.settings = list(axis.line = list(col = 'black')),
scales = list(draw = FALSE),
col.regions = colr,
at = seq(0, 10, len = 101)
)
sen <- getData('GADM', country = 'Senegal', level = 1)
p + layer(sp.polygons(sen))
如果您想添加经度和纬度,请从您的代码中删除 scales = list(draw = FALSE)
。
我试图在图层图中重叠大陆轮廓,并希望用经度和纬度值标记 x 轴和 y 轴。目前我没有收到错误,但没有出现轮廓。我想知道这是否是因为我没有正确定义纬度和经度轴?
library(rgdal)
library(rasterVis)
library(RColorBrewer)
library(ncdf4)
library(maptools)
f<-nc_open("cases5.nc")
cases<-ncvar_get(f,"cholera_cases")
sen<-getData('GADM', country='Senegal', level=1)
colr <- colorRampPalette(brewer.pal(11, 'RdYlBu'))
for (i in seq(1,1)){
name<-sprintf("plot_%03d.png",i)
png(name)
print(name)
p<-levelplot(cases,
margin=FALSE, # suppress marginal graphics
colorkey=list(
space='bottom', # plot legend at bottom
labels=list(at=0:10, font=4) # legend ticks and labels
),
par.settings=list(
axis.line=list(col='transparent') # suppress axes and legend outline
),
scales=list(draw=FALSE), # suppress axis labels
col.regions=colr, # colour ramp
at=seq(0, 10, len=101))
+layer(sp.polygons(sen, fill="transparent"))
print(p)
dev.off()
}
此处提供了示例 netcdf 数据文件:
我认为你需要将一个 RasterLayer
对象传递给 levelplot:
library(rgdal)
library(rasterVis)
library(RColorBrewer)
library(ncdf4)
library(maptools)
library(raster)
r <- raster("/Users/christopher/Downloads/cases5.nc")
colr <- colorRampPalette(brewer.pal(11, 'RdYlBu'))
p <- levelplot(
r,
margin = FALSE,
colorkey = list(space = 'bottom',
labels = list(at = 0:10, font = 4)),
par.settings = list(axis.line = list(col = 'black')),
scales = list(draw = FALSE),
col.regions = colr,
at = seq(0, 10, len = 101)
)
sen <- getData('GADM', country = 'Senegal', level = 1)
p + layer(sp.polygons(sen))
如果您想添加经度和纬度,请从您的代码中删除 scales = list(draw = FALSE)
。