[R] boxplot of raster and shapefile
Ivan Krylov
|kry|ov @end|ng |rom d|@root@org
Tue Aug 27 18:55:14 CEST 2024
В Mon, 26 Aug 2024 14:33:02 +0200
SIBYLLE STÖCKLI via R-help <r-help using 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
More information about the R-help
mailing list