在R中用ggplot绘制谷歌地图 [英] Plotting google map with ggplot in R

查看:242
本文介绍了在R中用ggplot绘制谷歌地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制

  library(ggmap)
al1 = get_map(location = c(lon = -86.304474,lat = 32.362563),zoom = 11,maptype ='roadmap')
al1MAP = ggmap(al1)
al1MAP


I am trying to plot Google map that is queried using RgoogleMaps package and combine it with 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.

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 codes:

#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. See ?get_map and ?ggmap for further options. An excellent resource is available in The R Journal

library(ggmap)
al1 = get_map(location = c(lon = -86.304474, lat = 32.362563), zoom = 11, maptype = 'roadmap')
al1MAP = ggmap(al1)
al1MAP

这篇关于在R中用ggplot绘制谷歌地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆