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))
alpha=0.5
outside the mapping definition, as you did with point colour above) and change the scaling of the points (see therange
parameter in?scale_size
) – Barrazascale_area(range=c(0,25))
did the trick. Thank for the tip @BenBolker – Suspiration