1

In R using the raster package, you can create box plots from two rasters (x and y) like so:

boxplot(x,y)

where:

x = Raster* object y = If x is a RasterLayer object, y can be an additional RasterLayer to group the values of x by 'zone'

Which works perfectly when I want to group the values of x by all the classes in my thematic raster y.

But if I only want to group the values in x by a subset of the thematic classes in y, is there a way to do this? I could replace any values in y outside the values I am interested with NODATA values, but I was hoping there a cleaner, simpler method.

2

I found that the value matching operator %in% works perfectly, to replace raster values I don't want (e.g., 4, 7, 10) with NA, and then I can call the boxplot method again.

y[y%in%c(4,7,10)] <- NA
1
  • you can also use thee subs or reclassify function – Robert Hijmans Oct 27 '15 at 2:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.