Skip to content

Instantly share code, notes, and snippets.

@schluedj
Created January 2, 2013 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schluedj/4437776 to your computer and use it in GitHub Desktop.
Save schluedj/4437776 to your computer and use it in GitHub Desktop.
Life expectancy visualization. Playing around with ggmap. Data from WHO.
#####################################
#Life expectancy data visualization
###################################
library(ggplot2)
library(mapproj)
library(ggmap)
###############################################
#Code for obtaining lat and longitude of countries
#This goes into google to get coordinates from google earth
####################################################
#life.data<-read.csv("~/Desktop/shiny/World_map/life_exp.csv")
#head(life.data)
#countries <- with(life.data,paste(country,sep=","))
#locs <- geocode(countries)
#head(locs)
#life.data<-data.frame(life.data,locs)
#head(life.data)
#write file so we don't have to wait as long
#write.csv(life.data, file="life_exp_fin.csv")
###Import data
life.data<-read.csv("~/Desktop/shiny/life_exp_fin.csv")
#pick place on map to center
map.center <- geocode("France")
#get map
gr<-get_map(location=c(map.center$lon,map.center$lat),zoom=3,maptype="hybrid")
#ggmap is very similar to
ggmap(gr,extent="panel")+geom_point(data=life.data,aes(x=lon, y=lat,size=life_exp_birth),alpha=.7,color="plum2")+ scale_size(name="life expectancy")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment