[R-sig-Geo] raser::boxplot : cannot add grouping layer

Agustin Lobo alobolistas at gmail.com
Wed Oct 7 11:44:50 CEST 2015


According to the help page of raster::boxplot
x: Raster* object
y: if x is a RasterLayer object, y can be an additional RasterLayer to
group the values of x by 'zone'

but I get an error when I add a raster layer that represents a classification:
r1 <- r2 <- r3 <- raster(ncol=10, nrow=10)
r1[] <- rnorm(ncell(r1), 100, 40)
r2[] <- rnorm(ncell(r1), 80, 10)
r3[] <- rnorm(ncell(r1), 120, 30)
s <- stack(r1, r2, r3)
names(s) <- c('A', 'B', 'C')

rc <- round(r1[[1]]/100)
hist(rc)
summary(rc)

boxplot(s[[1]],rc)

Error in as.data.frame.default(data) :
  cannot coerce class "structure("RasterLayer", package = "raster")"
to a data.frame

Am I not interpreting what this function is supposed to do? I want to
get the boxplot
of the values of s by class in rc
(i can do it having rc as an sp pol data frame and using extract,  but
thought raster::boxplot
would be a more direct way)

Thanks

Agus



More information about the R-sig-Geo mailing list