Dear community


I have two raster files (here r and r2: y-axis) and an equal x-axis (here s,
4 classes).

Instead of plotting two boxplots I would like to plot paired boxplots: for
each class the boxplots from r and r2 paired).

I tried to adapt the code, but I am struggling around with the error:



> names(rs) <- c('r', 's', 'r2')

Error in `names<-`(`*tmp*`, value = c("r", "s", "r2")) :

  incorrect number of layer names



Additionally I am not sure how to adapt the function boxplot() with two
rasters, r and r2 and not only r.



Kind regards

Sibylle



Working example:



library(raster)

r <- raster(nc=10, nr=5)

r[] <- runif(ncell(r), min=10, max=20) * 2



r2 <- raster(nc=10, nr=5)

r2[] <- runif(ncell(r2), min=10, max=20) * 2



s <- setValues(r, sample(c(1:4), replace = T, size=50))



rr2s <- stack(r, r2,s)

names(rs) <- c('r', 's', 'r2')



d <- as.data.frame(rr2s)

boxplot(r~s, data= d)




        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to