我计算了一个变量“final_factor”,我确信这是正确的。 当我尝试在地图上绘制这些数据以显示不同的值时,我知道加利福尼亚有一个最高值,但它显示为最低值之一。 我认为这与阿拉斯加和夏威夷没有出现在地图上有什么关系?但是我在矢量中有两个状态的名称:
states <- tolower(state.name)
#set up map with each state assigned color
library(maps)
library(maptools)
library(RColorBrewer)
library(classInt)
colors <- brewer.pal(4, "YlOrRd")
brks <- classIntervals(final_factor, n = 4, style = "quantile")
brks <- brks$brks
map("state", states, fill = TRUE, col = colors[findInterval(final_factor,
brks, all.inside = TRUE)])
legend("bottomright",legend = leglabs(round(brks)), fill=colors, bty="n")
打印状态向量:
[1] "alabama" "alaska" "arizona" "arkansas" "california" "colorado"
[7] "connecticut" "delaware" "florida" "georgia" "hawaii" "idaho"
[13] "illinois" "indiana" "iowa" "kansas" "kentucky" "louisiana"
[19] "maine" "maryland" "massachusetts" "michigan" "minnesota" "mississippi"
[25] "missouri" "montana" "nebraska" "nevada" "new hampshire" "new jersey"
[31] "new mexico" "new york" "north carolina" "north dakota" "ohio" "oklahoma"
[37] "oregon" "pennsylvania" "rhode island" "south carolina" "south dakota" "tennessee"
[43] "texas" "utah" "vermont" "virginia" "washington" "west virginia"
[49] "wisconsin" "wyoming"
修改
dput(final_factor)
c(13.1869132327146, 171.433398222877, 227.749810811086, -14.1974718516621,
292.389186491228, 323.12008421977, 114.024635203315, 115.364807676881,
-15.1754852331502, 734.284490062705, 269.496055219527, 102.184153210658,
158.712652916419, 130.193350846599, 85.401242006107, 69.0693461392464,
51.2137241459215, -16.4621737928579, 3.9800030829435, 134.228485903131,
124.324796014604, 61.4752893131643, 87.5287367394929, -4.17424693316761,
57.189969190164, -39.7709531142949, 39.0473843687773, 442.851878799144,
8.39115604207723, 58.2777093138021, 113.015962228309, 42.1084585526875,
43.450593458832, 69.4451485910943, 89.7861742132476, -7.04698794593079,
399.77348868168, 81.4518090799681, 46.4900462348408, 29.791135517089,
26.0230215593234, 25.5418598295709, 77.7971750603608, 27.5049376597005,
8.89091057653171, 183.184412938975, 557.92622323569, 75.0446703015732,
104.662393065438, 9.46344271308971)