Mexico City’s Metro Statistics
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.
[sourcecode language=”r”]
#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))
[/sourcecode]