[英]Overlay continent outlines on levelplot in R
I'm trying to overlap continent outlines on a layerplot, and would like to lable the x and y axes with longitude and latitude values. 我正在尝试在图层图上重叠大陆轮廓,并希望使x和y轴具有经度和纬度值。 At the moment I don't get an error but no outlines appear.
目前,我没有收到错误,但没有轮廓出现。 I am wondering if that is because I'm not defining the lat and lon axes correctly?
我想知道是否是因为我没有正确定义纬度和经度轴?
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()
}
An example netcdf datafile is available here: 此处提供了一个示例netcdf数据文件:
http://clima-dods.ictp.it/Users/tompkins/stackoverflow/cases5.nc http://clima-dods.ictp.it/Users/tompkins/stackoverflow/cases5.nc
I think you need to pass a RasterLayer
object to levelplot: 我认为您需要将
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))
If you want to add the longitude and latitude remove scales = list(draw = FALSE)
from your code. 如果要添加经度和纬度,请从代码中删除
scales = list(draw = FALSE)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.