[R-sig-Geo] Placing a world map on r plot

r@i@1290 m@iii@g oii @im@com r@i@1290 m@iii@g oii @im@com
Tue May 21 20:28:57 CEST 2019


I am trying to place a world map on my current plots made by level plot. This plot was made as follows:  
    library(raster)
    library(ncdf4)
    library(maps)
    library(maptools)
    library(rasterVis)
    library(ggplot2)
    library(rgdal)
    library(sp)
    library(gridExtra)    
MFplot4<-levelplot(MFMeaner3,margin=F, at=Fcutpoints4,cuts=11, 
    pretty=TRUE,par.settings=mapTheme, main="Historical five-day maximum   
    precipitation (mm/day) model mean")
The object "MFMeaner3" has the following attributes:    class       : RasterLayer 
    dimensions  : 64, 128, 8192  (nrow, ncol, ncell)
    resolution  : 2.8125, 2.789327  (x, y)
    extent      : -181.4062, 178.5938, -89.25846, 89.25846  (xmin, xmax, ymin, 
    ymax)
    coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
    data source : in memory
    names       : layer 
    values      : 0.1583802, 164.2064  (min, max)
Here was my attempt to place a world map overlay on the above plot:
    world.outlines<-map("world", plot=FALSE) 
    world.outlines.sp<-map2SpatialLines(world.outlines,proj4string =   
    CRS("+proj=longlat"))

    MFplot4 + layer(sp.lines(world.outlines.sp,col="black",lwd=0.5))However, this leads to the following error:
    Error: Attempted to create layer with no stat.
I also tried placing a simple world map using this:
    MFplot4 + plot(wrld_simpl)
But I receive this error:
    Error in UseMethod("as.layer") : 
    no applicable method for 'as.layer' applied to an object of class "NULL"
Why would these errors occur? 

Any assistance with this would be extremely appreciated!
	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list