简体   繁体   English

用R中的ggplot绘制谷歌地图

[英]Plotting google map with ggplot in R

I am trying to plot Google map that is queried using RgoogleMaps package and combine it with ggplot. 我正在尝试绘制使用RgoogleMaps包查询的Google地图 ,并将其与ggplot结合使用。 Ultimately, I want to show total population using geom_point , somewhat similar to the picture below however I am trying to concentrate on Montgomery region because of over-plotting. 最后,我想用geom_point显示总人口,有点类似于下图,但是由于过度绘图,我试图集中在蒙哥马利地区。

I am frustrated because I cannot plot my queried map in R. I tried a couple of packages such as read.jpeg and png but it didn't quite work out. 我很沮丧,因为我不能在R中绘制我查询的地图。我尝试了几个包,如read.jpegpng但它没有完全解决。

R codes: 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")

在此输入图像描述

EDIT: 编辑:

Here is my rough result. 这是我粗略的结果。 I still want to: 我还是想:

  • Change the scale of dots' size because they seem rather small on the map. 更改点的大小,因为它们在地图上看起来相当小。
  • Make dots transparent or not-filled so that the map is still visible. 使点透明或未填充,以便地图仍然可见。

在此输入图像描述

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))

Is this what you're after. 这就是你所追求的。 It uses the ggmap package, which simplifies the process. 它使用ggmap包,简化了流程。 See ?get_map and ?ggmap for further options. 有关更多选项,请参阅?get_map?ggmap An excellent resource is available in The R Journal 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM