Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when using RColorBrewer to plot

Tags:

r

r-raster

rgdal

I am trying to make a plot of a map from raster data. I am using this code:

library(raster)
library(rgdal)
library(classInt)
library(RColorBrewer)

NDII = raster("G:\\Sheyenne\\image_differencing\\NDII\\differenced.tif")
value.vector = values(NDII)
breaks.qt = classIntervals(value.vector, n = 6, style = "jenks", intervalClosure = "right")
print (plot(NDII, breaks=breaks.qt$brks, col = brewer.pal(6, "Set1")))

but this returns:

Error in print(plot(NDII, breaks = breaks.qt$brks, col = brewer.pal(6, : error in evaluating the argument 'x' in selecting a method for function 'print': Error in .asRaster(x, col, breaks, zrange, colNA, alpha = alpha) : could not find function "brewer.pal"

like image 563
Stefano Potter Avatar asked Oct 23 '25 17:10

Stefano Potter


1 Answers

You provide no reproducible example, and I can't reproduce your error. The following code, which is the same as yours using the reproducible example of the R logo as a raster (and with the shortcut of using NDII[] instead of storing values(NDII) in a variable) works just fine for me...

library(raster)
library(rgdal)
library(classInt)
library(RColorBrewer)

NDII = raster(system.file("external/rlogo.grd", package="raster"))
# next line is really slow, I'd advise to run crop(NDII, extent(0,20,0,20)) 
# before to make quick tests
breaks.qt = classIntervals(NDII[], n = 6, style = "jenks", 
                           intervalClosure = "right")
plot(NDII, breaks=breaks.qt$brks, col = brewer.pal(6, "Set1"))

Do you reproduce your error with this code? Maybe you can start with a new, fresh session?

enter image description here

like image 118
ztl Avatar answered Oct 26 '25 07:10

ztl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!