foursquare thinktostart r map data

Visualize Foursquare Check-ins with R

You can use this tutorial to visualize foursquare check-ins in the ThinkToStartR package with:

foursquare map r

Hey R-Fans! You sure all heard of Foursquare. It has more than 45 million users but it´s potential is not recognized by much people. So today I want to show you how easy it is to get your check-in history and visualize it with rCharts and a leaflet map.

The Foursquare app

To start we need to create a Foursquare app. We can do this at https://foursquare.com/developers/apps Visualize Foursquare Check-ins Click on the green “Create a new App” button. This leads you to the settings page for your new app. Enter a name and a website address for your app. You can be creative and type in whatever you want. Click on “Save Changes” but leave the screen open as we need to edit it later. On the overview screen you can now see your Client id and Client secret. We will need them for the authentication with R. foursquare create app

Authentication

The authentication with OAuth2 is a little bit tricky with the Foursquare API. I implemented in my ThinkToStartR package but I will improve it in the next time. To intstall the package use:

For some more information take a look here: http://thinktostart.wordpress.com/2014/03/23/thinktostartr-package/ The authentication then basically is one function call:

It will ask you to edit the Foursquare app settings. To do so go back to the app you created on the Foursquare website, click on “Edit this App” and add the URL at “Redirect URLs”. R foursquare redirect URL foursquare app R map   Then hit enter in your R console and the authentication will go on. Log in to your Foursquare account and allow the app to access your account. The function then returns a token which we will use for our API calls. Remember that you installed the ThinkToStartR package in the dev_mode. So it will disappear as soon as you close the R instance.

Get all the Data!

Ok after the authentication process the fun part can start. First we need to get the data and split the returned JSON in some smaller parts we can work with more easily: data This call returns your whole venue history. You might see the v argument at the end. This is actually the version of the Foursquare API you want to use. Foursquare uses the date for this. So it actually adds the current date. In the next step we process the JSON object even further and create a dataframe where we can save all the important information we need

 

Visualize Foursquare check-ins

Now that we have our dataframe we can visualize it with rCharts.

So let´s create our empty map object with:

We will calculate the mean longitude and latitude values of our venue history to set the initial view of our map. Because it wouldn´t make sense if most of your check-ins are in Germany but the initial view of the map shows the USA.

In the next step we will add a marker for every venue in the dataframe. We also create a popup for every marker which shows additional information.

And that´s it! Congratulations for creating your first foursquare check-ins map! You can now open it or save it by tipping in

You can find the whole code at github: https://github.com/JulianHill/RTutorials/blob/master/r_foursquare_map.r

Julian Hillebrand

During my time at university and learning about the basics of economics I started heavily exploring the possibilities and changes caused by digital disruptions and the process of digital transformation, whereby I focused on the importance of data and data analytics and combination with marketing and management.
My personal focus of interest lies heavily on technology, digital marketing and data analytics. I made early acquaintance with programming and digital technology and never stop being interested in following the newest innovations.

I am an open, communicative and curious person. I enjoy writing, blogging and speaking about technology.