17

我正在尝试绘制使用 RgoogleMaps 包查询的谷歌地图并将其与 ggplot 结合起来。最终,我想使用 显示总人口geom_point,有点类似于下图,但是由于过度绘图,我试图专注于蒙哥马利地区。

我很沮丧,因为我无法在 R 中绘制我查询的地图。我尝试了几个包,例如read.jpegand ,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))
4

1 回答 1

28

这就是你所追求的。它使用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

在此处输入图像描述

于 2012-04-24T20:16:18.620 回答