I need to add logo png image to my spplot as a map element. Can tell me the way how input logo as into spplot?? This is my r code.
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)
)
With grid.raster
you can include an image in your plot. Define a new list with it, and add it as a new component to your 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)
Please, next time provide a reproducible example.