Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在美国地图上绘制数据时出错_R_Dictionary_Ggplot2_Maptools - Fatal编程技术网

R 在美国地图上绘制数据时出错

R 在美国地图上绘制数据时出错,r,dictionary,ggplot2,maptools,R,Dictionary,Ggplot2,Maptools,我计算了一个变量“final_factor”,我确信它是正确的。 当我试图在地图上绘制这些数据以显示不同的值时,我知道加利福尼亚州的值是最高的,但它显示的值是最低的。 我认为这与阿拉斯加和夏威夷没有出现在地图上有关?但我在向量中有两个州的名字: states <- tolower(state.name) #set up map with each state assigned color library(maps) library(maptools) library(RColorBrew

我计算了一个变量“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")
编辑

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)

a
dput(最终系数)
wl会有帮助。谢谢,我编辑了@hrbrmstr
final\u系数如何映射到州名称?
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)