# Mexico City’s Metro Statistics

June 24, 2012
By

(This article was first published on Jose Gonzalez .org » R, and kindly contributed to R-bloggers)

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

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=&quot;white&quot;, xlab=&quot;Longitude&quot;, ylab=&quot;Latitude&quot;)
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 = &quot;point&quot;)

#Full map
r r #print map
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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

## Recent popular posts

Contact us if you wish to help support R-bloggers, and place your banner here.

# Never miss an update! Subscribe to R-bloggers to receive e-mails with the latest R posts.(You will not see this message again.)

Click here to close (This popup will not appear again)