— Jose Gonzalez

Archive
R

I’ve struggled all morning on how to set shapefile encodings in R. Finally I got this solution to handle both French and Spanish characters.

Happy coding!

Read More

Average sentiment score

Twitter simultaneously allows people to be heard and to hear, easily and in real time, bringing with it potentially fascinating and ground breaking insights for anybody trying to take the public’s pulse on a hot issue.  It is almost mandatory that so much benefit comes with its challenges, namely how to process the humongous amounts of data available every minute. Never one to shy away from some super number crunching, this post is the first one of a series on Twitter.

The chart above represents more than 200,000 mentions of the twitter account belonging to Mexico’s President Enrique Peña Nieto during the past 20 days. It is intended as a proxy of how popular the President of Mexico is on Twitter. Every tweet was analyzed and scored as either positive or negative. Then the total number of positive/negative tweets per hour was recorded and divided by the total number of tweets in that hour. The results show, that on average, Peña Nieto has had a positive sentiment score (0.54) but there are severe hourly negative spikes.

If you would like to know more about how the calculations were elaborated, continue reading

Read More

Poverty and crime in Mexico

How safe is Mexico? That is a frequent question people ask me. There is even a  website about it  (see this blog post). So I’ve decided it was time to go one step further and make an interactive map (click here for full screen) of poverty and crime in Mexico.

The objective was to see which municipalities have higher crime rates and visually check if municipalities with higher crime rates also have high poverty rates. While unfortunately,  the most recent poverty data at the municipality level is for 2010 while the crime data, at the same level, is only available for 2011, 2012, 2013, I was still able to glean some interesting insights.

The interactive map´s main take away is that high rates of selected crimes are concentrated in just a few municipalities. Moreover, there appears to be no direct link to high poverty rates.

To do the analysis I used R, QGIS and TileMill, all that code is freely available in my github account. If you are interested in learning more about how I made the map, keep reading!

Read More

This is a short but sweet post on how to create a geojson file in R .  Remember that you can render geojson files in github.

 

Read More

The White House This post shows how to use Google Maps‘ API with R making some tweaks to this function. Combine the first part with sapply or Plyr and it becomes a very powerful tool in just a few lines of code. You can find a gist in RMarkdown with the code here or click below to continue reading.

Read More

Bubble map of the Metro

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.

Read More