Site icon R-bloggers

Mexico City’s Metro Statistics

[This article was first published on Jose Gonzalez .org » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I used R and ggplot2 to make a bubble map of Mexico City’s Metro passenger count from January to February 2012. The statistics are stunning, some stations for example Indios Verdes, reached 10 million passengers in jus three months. You can see the code below and get the data for the project here.

#Statistical analysis of Mexico City's Metro
#Author Jose Gonzalez
#Website www.jose-gonzalez.org

## Load packages
library(ggplot2)
data(diamonds)
library(RColorBrewer)
library(foreign)
#Read data form excel
afluencia afluencia[1:10,]

# Simple Bubble plot
#Declare factor to choose colors
ff radius mycolor symbols(data$longitude, data$latitude, circles=radius, inches=0.1, fg=ff, bg="white", xlab="Longitude", ylab="Latitude")
text(data$longitude, data$latitude, data$estacion, cex=0.3)

#### ggplot
#Define layer
ggplot() +
layer(
  data = afluencia, mapping = aes(x = longitude, y = latitude, colour=factor(linea)),
  geom = "point")

#Full map
r r #print map
##Add customized colors
rc rc # print map

## Manually adjust the colors for each line
cols ## Add text labels
rc + scale_colour_manual(values = cols) + geom_text(aes(label = estacion), hjust=-0.1, vjust=0)

## Map inset focus on Downtown
rc + scale_colour_manual(values = cols) + geom_text(aes(label = estacion), hjust=-0.1, vjust=0) + coord_cartesian(xlim=c(-99.15, -99.10), ylim=c(19.40, 19.45))

The post Mexico City’s Metro Statistics appeared first on Jose Gonzalez .org.

To leave a comment for the author, please follow the link and comment on their blog: Jose Gonzalez .org » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.