[英]Plotting google map with ggplot in R
我正在尝试绘制使用RgoogleMaps包查询的Google地图 ,并将其与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))
这就是你所追求的。 它使用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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.