a.u*_*ite 5 plot r raster rastervis
我正在尝试使用定义的配色方案绘制栅格,该配色方案是从 Rcolorbrewer 包中获取的,到目前为止没有问题。raster\xc2\xb4s 值范围从 0 到 1,没有 NA\xc2\xb4s。
\n\nlibrary(RColorBrewer)\nlibrary(classInt)\n\npal <- brewer.pal(n=50, name = "RdYlGn")\nplot(rw_start_goal_stan, col=pal)\nRun Code Online (Sandbox Code Playgroud)\n\n
现在我尝试包含分位数分隔符,这是我使用 ClassInt 包计算的
\n\nlibrary(RColorBrewer)\nlibrary(classInt)\n\npal <- brewer.pal(n=50, name = "RdYlGn")\nbreaks.qt <- classIntervals(rw_start_goal_stan@data@values, style = "quantile")\nplot(rw_start_goal_stan, breaks = breaks.qt$brks, col=pal)\nRun Code Online (Sandbox Code Playgroud)\n\n错误的是,plot() 仅将配色方案应用于值范围的 50%,其余部分保持白色。
\n\n
我究竟做错了什么?
\n编辑:使用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
Run Code Online (Sandbox Code Playgroud)
您需要指定颜色数量,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")
Run Code Online (Sandbox Code Playgroud)
来源:R 中的地图