Rain1290
Rain1290

Reputation: 35

Error with plotting: "Error in do.call("constructMargin", margin) : second argument must be a list"

I am using levelplot to make a raster layer of my precipitation data, as shown below. Oddly enough, when I ran the following code previously, it went through just fine, but now, without any change made to the code, I have been experiencing a strange error, and there is little known about it online. Here is what I have done:

library(raster)
library(maptools)
library(rasterVis)
library(sp)
library(gridExtra)
library(grid)
library(RColorBrewer)


FPrec <- brick(Fncfname,var="fivedaymax") #making a raster brick
Fr <- abs(init(raster(), 'y'))
Fsm <- mean(FPrec, na.rm=TRUE) #calculates the mean into a raster layer
Fw <- init(FPrec, 'y')
Fw <- cos(Fw*(pi/180)) #creates weights to account for grid cell size 
discrepancies
Fx <- Fsm*Fw #applying the weights to each grid cell
FmapTheme <- rasterTheme(region=rev(brewer.pal(10,"Spectral")))
cutpoints <- c(200,175,150,125,100,75,50,25,0)
levelplot(Fx,margin=F,at=cutpoints,cuts=11,pretty=TRUE,par.settings=FmapTheme, main="Test variable 
for CanESM2") 

The "levelplot" is where the problem occurs. I receive the following error:

Error in do.call("constructMargin", margin) : second argument must be a list

The object "Fsm" has the following attributes:

Fsm

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)
crs        : +proj=longlat +datum=WGS84 
source     : memory
names      : layer 
values     : 1.949589, 627.0804  (min, max)

What could be causing this seemingly random error? I tried running the same thing in other versions of R (or in a new workspace), but the same problem occurs. It's something in levelplot that is causing it, but I cannot see anything obvious, especially since this code worked just fine previously).

Any help with this would be greatly appreciated!

Upvotes: 0

Views: 120

Answers (0)

Related Questions