我正在尝试绘制具有定义的配色方案的栅格,该栅格取自Rcolorbrewer软件包,到目前为止没有问题。栅格的值范围从0到1,无NA。

library(RColorBrewer)
library(classInt)

pal <- brewer.pal(n=50, name = "RdYlGn")
plot(rw_start_goal_stan, col=pal)




现在我尝试包括分位数间隔,我使用ClassInt包计算得出

library(RColorBrewer)
library(classInt)

pal <- brewer.pal(n=50, name = "RdYlGn")
breaks.qt <- classIntervals(rw_start_goal_stan@data@values, style = "quantile")
plot(rw_start_goal_stan, breaks = breaks.qt$brks, col=pal)


错误地,plot()仅将颜色方案应用于值范围的50%,其余的保持白色。



我究竟做错了什么?

最佳答案

编辑:使用OP和rasterVis::levelplot解决方案从this answer提供的数据

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


r - R绘图栅格颜色方案不完整-LMLPHP



您需要在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")


资料来源:Maps in R

关于r - R绘图栅格颜色方案不完整,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49910270/

10-12 23:45