【发布时间】:2025-12-21 05:00:11
【问题描述】:
我正在 R 中制作阴影图。图例为零和缺失创建单独的类别,但将它们都标记为“[0,0)”
知道如何解决这个问题吗?
library(gpclib)
library(maptools) # loads sp library too
library(RColorBrewer) # creates nice color schemes
library(classInt) # finds class intervals for continuous variables
CAcounty.shp <- readShapePoly(file.choose(),proj4string=CRS("+proj=longlat"))
plotvar <- CAcounty.shp@data$mediresp
nclr <- 8
plotclr <- brewer.pal(nclr,"BuPu")
class <- classIntervals(plotvar, nclr, style="quantile")
colcode <- findColours(class, plotclr)
plot(CAcounty.shp, xlim=c(-122.5, -117), ylim=c(32,42))
plot(CAcounty.shp, col=colcode, add=T)
XXXXX <- read.csv("XXXXXXXX.csv")
plotvar <- XXXXX$XXXXXX
title(main=“XXXXXXXXXXXXXXXX",
sub=“Internal Data")
legend(-119, 42, legend=names(attr(colcode, "table")),
fill=attr(colcode, "palette"), cex=0.6, bty="n")
plotclr <- brewer.pal(nclr,"RdYlGn")
colcode <- findColours(class, plotclr)
points(KPhosp$lon, KPhosp$lat, pch=16, col=colcode, cex=1)
【问题讨论】:
-
names(attr(colcode,'table'))在两种情况下都返回相同的文本字符串不是真正的问题吗? -
大部分代码与问题无关。您不需要地图的东西来显示问题,只需生成 plotvar 和 plotclr 并给我们一些我们可以剪切和粘贴的东西。
-
我无法获得图例来为我提供 any 类别的缺失数据。 耸耸肩