Add a line plot in stack of rasters in spplot R

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Add a line plot in stack of rasters in spplot R



I have a stack of rasters.


## read the libraries
library(raster)
library(rgdal)
library(sp)

##random raster object
r <- raster(ncol=40, nrow=20)
r <- rnorm(n=ncell(r))
# Create a RasterStack object with 3 layers
s <- stack(x=c(r, r*2, r**2))

##coordinate system
wgs<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")

##plotting with spplot
plot(spplot(s,layout=c(2,2),
colorkey =list(space = "right"),
names.attr = c("a","b","c")))



enter image description here



So far, I have plotted the stack of raster in layout=c(2,2). Now, in the empty 2nd row and 2nd column I want to plot the mean of raster stack as a line plot. Something like this....


layout=c(2,2)


plot(cellStats(s, stat='mean', na.rm=TRUE,
asSample=TRUE),type="l",ylab="mean",xlab="value")



Can anyone help me with this?



enter image description here









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard