使用RColorBrewer绘图时出错

时间:2017-02-20 01:25:50

标签: r r-raster rgdal

我正在尝试从栅格数据绘制地图。我正在使用此代码:

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")))

但这会返回:

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"

1 个答案:

答案 0 :(得分:2)

您没有提供可重现的示例,我无法重现您的错误。 以下代码与您的相同,使用R徽标的可重现示例作为栅格(并使用NDII[]的快捷方式而不是将values(NDII)存储在变量中)对我来说很好...

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"))

您是否使用此代码重现错误?也许你可以从一个新的,新的会议开始?

enter image description here