当我绘制纽约所有县的地图时,我得到了正确的等值线地图。但是,当我剪裁地图时,颜色变得看似随机。这是一个示例,我只是根据县名将县分为 5 个类别。
library(maps)
library(mapproj)
library(RColorBrewer)
map1 <- map("county", region="New York", plot=FALSE)
ny <- c(1:62)
ny2 <- data.frame(ny)
#define map colors
clr <- (brewer.pal(5, "Spectral"))
#define quantiles
map2 <- within(ny2, quartile <- as.integer(cut(ny, quantile(ny,probs=0:5/5), include.lowest=TRUE)))
map2$colorbuckets <- cut(map2$quartile, breaks=5)
#all of ny - colors are correct
map("county", border="gray", regions = "New York", fill=TRUE, projection="simpleconic",
par=c(30,45), col=clr[map2$colorbuckets])
box()
#subset of ny - colors are not correct, seemingly random
map("county", regions="New York", xlim=c(-74.5,-73), ylim=c(40.48,43.9),
border="gray", fill=TRUE, exact=TRUE, col=clr[map2$colorbuckets])
box()