В Mon, 26 Aug 2024 14:33:02 +0200
SIBYLLE STÖCKLI via R-help <r-help@r-project.org> пишет:

> > # Extract raster values within the shapefile
> > extracted_values <- extract(raster_file, shape_file)

> > # Assuming the shapefile has multiple polygons and you want to
> > # create a boxplot for each
> > data_list <- lapply(1:length(extracted_values), function(i) {  
> +     data.frame(value = extracted_values[[i]], polygon = i)
> + })
> > data <- do.call(rbind, data_list)  

> > names(data)  
> [1] "value"   "polygon"
 
> > # Create the boxplot
> > bp<-ggplot(data, aes(x = factor(polygon), y = value)) +  
> +     geom_boxplot() +
> +     labs(x = "Polygon", y = "Raster Values") +
> +     theme_minimal()
> > bp  
> Error in UseMethod("depth") : 
>   no applicable method for 'depth' applied to an object of class
> "NULL"
> In addition: Warning message:
> Removed 452451 rows containing non-finite outside the scale range
> (`stat_boxplot()`). 

Thank you for providing a runnable example! Could you please also show
the output of str(extracted_values) and str(data)?

-- 
Best regards,
Ivan

______________________________________________
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