ニューヨークのすべての郡をマッピングすると、正確なコロプレス マップが得られます。ただし、マップをクリッピングすると、色が一見ランダムになります。これは、郡名に基づいて郡を 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()