编辑:使用此答案中的 OP 和rasterVis::levelplot
解决方案提供的数据
library(raster)
library(rasterVis)
library(classInt)
plotVar <- raster("LCPs_standartized.tif")
nColor <- 50
break1 <- classIntervals(plotVar[!is.na(plotVar)],
n = nColor, style = "quantile")
lvp <- levelplot(plotVar,
col.regions = colorRampPalette(brewer.pal(9, 'RdYlGn')),
at = break1$brks, margin = FALSE)
lvp
您需要指定颜色的数量,classIntervals
然后为该classInterval
对象分配颜色代码。
library(RColorBrewer)
library(classInt)
plotVar <- rw_start_goal_stan@data@values
nColor <- 50
plotColor <- brewer.pal(nColor, name = "RdYlGn")
# equal-frequency class intervals
class <- classIntervals(plotVar, nColor, style = "quantile")
# assign colors to classes from classInterval object
colorCode <- findColours(class, plotColor)
# plot
plot(rw_start_goal_stan)
plot(rw_start_goal_stan, col = colorCode, add = TRUE)
# specify the location of the legend, change -117 & 44 to numbers that fit your data
legend(-117, 44, legend = names(attr(colorCode, "table")),
fill = attr(colorCode, "palette"), cex = 0.8, bty = "n")
资料来源:R 中的地图