Add a line plot in stack of rasters in spplot R
Clash 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")))
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?
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.