如何编辑 R 函数 spplot 中的调色板栏?
How to edit the palette bar in the R function spplot?
我正在使用 R 包 GWmodel。在绘制 GWR 的输出时,我发现自己无法在 ssplot 函数中编辑侧边栏。
我使用的几行代码(数据已经在包中)就足够了。你只需要安装GWmodel库:
library(GWmodel)
data("DubVoter")
bw.gwr.1 <- bw.gwr(GenEl2004 ~ DiffAdd + LARent + SC1 + Unempl + LowEduc + Age18_24 + Age25_44 + Age45_64, data = Dub.voter, approach = "CV", kernel = "gaussian", adaptive = FALSE)
gwr.res <- gwr.basic(GenEl2004 ~ DiffAdd + LARent + SC1 + Unempl + LowEduc + Age18_24 + Age25_44 + Age45_64, data = Dub.voter, bw = bw.gwr.1, kernel = "gaussian", adaptive = FALSE, F123.test = TRUE)
Greens <- c("#238B45","#74C476","#BAE4B3","#EDF8E9")
spplot(gwr.res$SDF, "Unempl", cuts = 4, at = c(fivenum(gwr.res$SDF$Unempl)), col.regions = Greens)
结果如下:
正如您在 spplot 函数中所见,参数 at 的值为 c(fivenum(gwr.res$SDF$Unempl)),对应于最小值、第一四分位数、中位数、第三四分位数、 gwr.res$SDF$Unempl 中的最大值。查看图表,我们可以看到颜色将此分区划分为 4 类(使用参数 cuts = 4 at = c(fivenum(gwr.res$SDF$Unempl)))。
我想做的是用调色板编辑边栏并添加替换 6,4,2,0,-2 为 c(fivenum(gwr.res$SDF$Unempl )) 是:
-2.427,-0.916,-0。 6.706, -0.494, 7.566
这是有效的代码:
labelat = fivenum(gwr.res$SDF$Unempl)
labeltext = labelat
spplot(gwr.res$SDF, "Unempl", cuts = 4, at = c(fivenum(gwr.res$SDF$Unempl)), col.regions = Greens,
colorkey=list(width=0.3,
space="right",
tick.number=5,
labels=list(
at=labelat,
labels=labeltext )))
请注意,边栏上的值不同于 -2.427、-0.916、-0。 6.706, -0.494, 7.566 因为数据不同。
我正在使用 R 包 GWmodel。在绘制 GWR 的输出时,我发现自己无法在 ssplot 函数中编辑侧边栏。
我使用的几行代码(数据已经在包中)就足够了。你只需要安装GWmodel库:
library(GWmodel)
data("DubVoter")
bw.gwr.1 <- bw.gwr(GenEl2004 ~ DiffAdd + LARent + SC1 + Unempl + LowEduc + Age18_24 + Age25_44 + Age45_64, data = Dub.voter, approach = "CV", kernel = "gaussian", adaptive = FALSE)
gwr.res <- gwr.basic(GenEl2004 ~ DiffAdd + LARent + SC1 + Unempl + LowEduc + Age18_24 + Age25_44 + Age45_64, data = Dub.voter, bw = bw.gwr.1, kernel = "gaussian", adaptive = FALSE, F123.test = TRUE)
Greens <- c("#238B45","#74C476","#BAE4B3","#EDF8E9")
spplot(gwr.res$SDF, "Unempl", cuts = 4, at = c(fivenum(gwr.res$SDF$Unempl)), col.regions = Greens)
结果如下:
正如您在 spplot 函数中所见,参数 at 的值为 c(fivenum(gwr.res$SDF$Unempl)),对应于最小值、第一四分位数、中位数、第三四分位数、 gwr.res$SDF$Unempl 中的最大值。查看图表,我们可以看到颜色将此分区划分为 4 类(使用参数 cuts = 4 at = c(fivenum(gwr.res$SDF$Unempl)))。
我想做的是用调色板编辑边栏并添加替换 6,4,2,0,-2 为 c(fivenum(gwr.res$SDF$Unempl )) 是:
-2.427,-0.916,-0。 6.706, -0.494, 7.566
这是有效的代码:
labelat = fivenum(gwr.res$SDF$Unempl)
labeltext = labelat
spplot(gwr.res$SDF, "Unempl", cuts = 4, at = c(fivenum(gwr.res$SDF$Unempl)), col.regions = Greens,
colorkey=list(width=0.3,
space="right",
tick.number=5,
labels=list(
at=labelat,
labels=labeltext )))
请注意,边栏上的值不同于 -2.427、-0.916、-0。 6.706, -0.494, 7.566 因为数据不同。