我正在尝试绘制使用RgoogleMaps包查询的Google map并将其与ggplot结合使用。最后,我想使用geom_point
显示总人口,有点类似于下图,但是由于过度绘图,我试图集中在蒙哥马利地区。
我感到很沮丧,因为我无法在R中绘制我查询过的地图。我尝试了几个包,例如read.jpeg
和png
但是它没有完全解决。
R代码:
#query google map
al1 <- GetMap(center=c(32.362563,-86.304474), zoom=11, destfile = "al2.jpeg",
format="jpg",maptype="roadmap")
#load only specific states
alabama <- subset(all_states, region %in% c("alabama"))
#population
p1 <- ggplot()
p1 <- p1 + geom_polygon(data=alabama,
aes(x=long, y=lat, group=group), colour="white", fill="grey10")
p1 <- p1 + geom_point(data=quote, aes(x=IntPtLon, y=IntPtLat, size=TotPop,
color=TotPop),colour="coral1") + scale_size(name="Total Pop")
修改
这是我的粗略结果。我还是想:
al1 <- get_map(location = c(lon = -86.304474, lat = 32.362563), zoom = 11, maptype = 'terrain')
al1MAP <- ggmap(al1)+ geom_point(data=quote_mgm, aes(x=IntPtLon, y=IntPtLat, size=TotPop))
答案 0 :(得分:27)
这就是你所追求的。它使用ggmap
包,简化了流程。有关更多选项,请参阅?get_map
和?ggmap
。 The R Journal
library(ggmap)
al1 = get_map(location = c(lon = -86.304474, lat = 32.362563), zoom = 11, maptype = 'roadmap')
al1MAP = ggmap(al1)
al1MAP