Dear Ivan Dear community Quite nice book recommendation. Yes indeed my raster "s" (the shape file for the boxplot classes) has several layers. That's way I tried to select a layer by " s<-sf$Unterregio".> sf <- read_sf("C:/Users/....._BiogeoRegion.shp") > names(sf)> names(sf)[1] "RegionNumm" "RegionName" "Unterregio" "Unterreg_1" "ObjNummer" "Version" "Shape_Leng" "Shape_Area" "DERegionNa" "FRRegionNa" "ITRegionNa" "DEBioBedeu" "FRBioBedeu" "ITBioBedeu" [15] "geometry"> s<-sf$Unterregio > r<-allrasters_pres[[1]]Kind regards Sibylle -----Original Message----- From: Ivan Krylov <ikrylov at disroot.org> Sent: Friday, August 23, 2024 5:30 PM To: sibylle.stoeckli at gmx.ch Cc: 'SIBYLLE ST?CKLI via R-help' <r-help at r-project.org> Subject: Re: [R] paired raster boxplots ? Fri, 23 Aug 2024 10:15:55 +0200 <sibylle.stoeckli at gmx.ch> ?????:> > s<-sf$Unterregio > > r<-allrasters_pres[[1]] > > > > > > rs <- stack(r, s) > > names(rs) <- c('r', 's') > Error in `names<-`(`*tmp*`, value = c("r", "s")) : > incorrect number of layer namesIt looks like at least one of the rasters 'r' and 's' has multiple layers. What does names(rs) return? I would offer more detailed advice, but I don't know 'raster' that well. The "R Inferno" book [1] offers a lot of generic-R troubleshooting advice, which should help you progress past errors like this one without waiting for someone on R-help to reply. -- Best regards, Ivan [1] https://www.burns-stat.com/documents/books/the-r-inferno/
? Sat, 24 Aug 2024 10:24:36 +0200 <sibylle.stoeckli at gmx.ch> ?????:> Yes indeed my raster "s" (the shape file for the boxplot classes) has > several layers.If 's' contains more than one layer, then this already prevents you from giving two names to stack(r, s).> That's way I tried to select a layer by " > s<-sf$Unterregio".'sf' is a data.frame-like object returned by read_sf, not a raster. If 's' is a raster, it could still contain multiple layers.> > sf <- read_sf("C:/Users/....._BiogeoRegion.shp") > > names(sf) > > > names(sf) > [1] "RegionNumm" "RegionName" "Unterregio" "Unterreg_1" "ObjNummer" > "Version" "Shape_Leng" "Shape_Area" "DERegionNa" "FRRegionNa" > "ITRegionNa" "DEBioBedeu" "FRBioBedeu" "ITBioBedeu" > [15] "geometry" > > > s<-sf$Unterregio > > r<-allrasters_pres[[1]]Sorry, that's still not enough information because we don't know what names(rs) is. Since 'allrasters_pres' is a list of rasters, 'r' could also contain more than one layer, resulting in stack(r, s) containing more than two layers. In order to avoid the error, you need to see names(rs) and either give the same number of names to the object instead of two, or additionally extract one layer (using raster(r, layer = NUMBER_OR_NAME)) from each of 'r' and 's' before stacking them. -- Best regards, Ivan