我需要将logo png图像作为地图元素添加到我的spplot中。可以告诉我输入标识如何进入spplot? 这是我的代码。
im <- raster("LMB_KBDI_2013-01-01.tif")
proj <- CRS('+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0')
#Plot SPPlot
mrc <- readShapePoly('E:/MRC/LMB_Country.shp', proj4string=proj)
polys <- list("sp.lines", as(mrc, "SpatialLines"), col="black")
DROUGHTcolors <- colorRampPalette(c("lightyellow","yellow","orange","red"))
north <- list("SpatialPolygonsRescale", layout.north.arrow(), offset=c(107.5,20), scale=1.5)
txt1 <- list("sp.text", c(100,9.8), "0`")
txt2 <- list("sp.text", c(102,9.8), "2`")
scale <- list("SpatialPolygonsRescale", layout.scale.bar(), offset=c(100,10), scale=2, fill=c("transparent","black"))
img.layout <- list(polys, north,txt1, txt2, scale)
CUTS1 <- c(0, 200, 400, 600, 800)
CUTS11 <- c(100, 300, 500, 700)
spplot(
im,
sp.layout=img.layout,
col.regions = DROUGHTcolors,
scales=list(draw=TRUE),
colorkey=list(
draw=TRUE, space = "right", at=CUTS1,
labels=list(
at=CUTS11,
labels=c(
"Normal","Abnormally Dry","Moderate Dry","Severe Dry"
), cex.lab= 1.5
)
),
at=CUTS1, main = list(paste("Drought Map of Lower Mekong River Basin -"), cex=2)
)
答案 0 :(得分:2)
使用grid.raster
,您可以在地块中添加图片。使用它定义新列表,并将其作为新组件添加到img.layout
:
library(grid)
library(png)
img <- readPNG(system.file("img", "Rlogo.png", package="png"), native=TRUE)
## Define x, y, and width/height to position and resize the logo
logo <- list("grid.raster", img,
x = x, y = y, width = width,
default.units='native')
img.layout <- list(polys, north,txt1, txt2, scale, logo)
spplot(im, sp.layout=img.layout)
请下次提供可重现的例子。