Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

enter image description here

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.

enter image description here

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))
like image 741
Ken Avatar asked Apr 24 '12 16:04

Ken


1 Answers

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

enter image description here

like image 113
Sandy Muspratt Avatar answered Sep 20 '22 22:09

Sandy Muspratt