我有一份加利福尼亚地图。 奶粉编码按组群分类,从低端到高压,共分五组,并配有色。 我想做的是,在人口密度的基础上,将热图层置于这一位置上,但此时我无法做到这一点。
我知道,我需要根据人口密度来改变甲型六氯环己烷,这只是数据框架中的密度,但我不知道如何做到这一点。
任何帮助都将受到高度赞赏。 我在地图上有一层,但甲型六氯环己烷是恒定的,而不是因人口密度而异。
我的守则是:
第一,建立可使用的数据框架:
stack_reduced_lng=c(-118.2495, -118.2467, -118.2737, -118.3108, -118.3065, -118.2942, -118.2849, -118.3471, -118.3158, -118.2587, -118.2382, -118.2403, -118.2665, -118.3546, -118.2643, -118.3172, -118.3387, -118.3099, -118.1561, -118.1999)
stack_reduced_lat=c( 33.97398, 33.94901, 33.96411, 34.07621, 34.05912, 34.04801, 34.02809, 34.00956, 34.06211, 34.00714, 34.06599, 34.04481, 34.03939, 34.02872, 34.05291, 34.02887, 34.04864, 34.06639, 34.02453, 34.02276)
stack_reduced_density=c( 6595.9, 6721.1, 8016.2, 7668.7, 14151.8, 11981.7, 6640.7, 3337.9, 3226.8, 10014.5, 4361.8, 7227.4, 5112.6, 4886.0, 14737.8, 7131.7, 6408.5, 13386.6, 5905.2, 4266.7)
stack_reduced_value.level=c( "Lower.Value", "Lower.Value", "Lower.Value", "Upper.Mid.Value", "Middle.Value", "Low.Mid.Value", "Low.Mid.Value", "Middle.Value", "Middle.Value", "Lower.Value", "Low.Mid.Value", "Middle.Value", "Middle.Value", "Low.Mid.Value", "Middle.Value", "Low.Mid.Value", "Middle.Value", "Low.Mid.Value", "Low.Mid.Value", "Low.Mid.Value")
df=as.data.frame(cbind(stack_reduced_lng, stack_reduced_lat, stack_reduced_density, stack_reduced_value.level))
colnames(df)=c("lng", "lat", "density", "value.level")
接下来是制定原始清单的法典:
#### First, our center
la.center=c(lng=-118.2437, lat=34.0522)
#### We will create a vector of colors, to be names and used in all project maps.
map_colors=c("black", "yellow", "green", "blue", "red")
#### creating our map
socal_map=get_map(location=la.center, zoom=6, scale=4)
d=ggmap(socal_map)+
geom_point(aes(x=lng, y=lat, color=as.factor(value.level)), data=df)
#ggtitle("Map of Home Values By Zip Code For California")
#### Formatting the map
d=d+scale_color_manual(, name="Home Value Level", breaks=c("Lower.Value","Low.Mid.Value","Middle.Value", "Upper.Mid.Value", "Upper.Value"), labels=c("Lower Home Value", "Lower Middle Home Value", "Middle Home Value", "Upper Middle Home Value", "Upper Home Value"), values=map_colors)+labs(x="Longititude", y="Latitude", title="Map of Home Values by Zip Code for California")
上述法典制定了理想的地图,但我要给它增加一个热图层。
我在此试图:
d+coord_cartesian()+stat_binhex(
aes(x=lng, y=lat, fill=density),
size=1, bins=20, alpha=0.5,
data=df
)
这给我的地图增加了一层,但甲型六氯环己烷的固定水平为0.5,因此与密度没有差别,这是我想要做的。 绘制的地图中,甲型六氯环己烷的浓度水平会随着密度的不同而变化。
Any help is greatly appreciated.
谢谢!