这是我绘制R的R代码:
User
但是,有一个县只显示为空白白色(尽管在其他县中价值最高)。代码有问题吗?我已经检查了实际值,它是一个有效的数值。
答案 0 :(得分:0)
问题在于您在ssplot
中使用它作为参数数字值,因此颜色开始“回收”。您需要使用通过RRmean
函数转换的classIntervals
。如果没有它,您将观察到与下面左图所示相似的结果。请查看下面的代码(带有Philladelphia Homicide Rate dataset):
library(rgdal)
library(sp)
library(ggplot2)
library(RColorBrewer)
library(classInt)
dsn <- "Philly3"
philly <-readOGR(dsn=dsn, layer = "Philly3") #
pal <- brewer.pal(9, "OrRd")
breaks_qt <- classIntervals(philly$HOMIC_R, n = 7, style = "quantile")
br <- breaks_qt$brks
offs <- 0.0000001
br[1] <- br[1] - offs
br[length(br)] <- br[length(br)] + offs
philly$HOMIC_R_bracket <- cut(philly$HOMIC_R, br)
g1 <- spplot(philly, "HOMIC_R", col.regions = pal, main = "Philadelphia homicide, with numerical value")
g2 <- spplot(philly, "HOMIC_R_bracket", col.regions = pal, main = "Philadelphia homicide, with categorical values")
library(gridExtra)
grid.arrange(g1, g2, nrow = 1)
输出: