[R] paired raster boxplots

sibyiie@stoeckii m@iii@g oii gmx@ch sibyiie@stoeckii m@iii@g oii gmx@ch
Thu Aug 22 08:46:03 CEST 2024


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]]



More information about the R-help mailing list