R Ready to Map Unit 2: Mapping Twitter Data

Dorris Scott
3/28/2018

Unit Objectives

  • To understand the basic functions of the leaflet for R package.
  • To mapped geotagged tweets.

Lesson 1: Understanding Leaflet

What is leaflet?

  • Tweets about the Paralympics

Lesson 1: Understanding Leaflet

Install the leaflet package and load it.

install.packages("leaflet")
library(leaflet)

If you are getting error messages about packages missing then:

install.packages("leaflet", dependencies = TRUE)
library(leaflet)

Lesson 2: Mapping Geotagged Tweets

Adding latitude and longitude information to the tweets(using the rtweet package)

  • Using the tweets collected about farmer's markets
fm <- lat_lng(FMTweets)

Lesson 2: Mapping Geotagged Tweets

Using leaflet

leaflet(fm) %>%
  addTiles() %>%
  addCircles(lng = ~lng, lat = ~lat, popup = fm$text, weight = 8, radius = 40, color = "blue", stroke = 
               TRUE, fillOpacity = 0.8)

Lesson 2: Mapping Geotagged Tweets

What issue do you see with this map?

Lesson 2: Mapping Geotagged Tweets

It's your turn!

  • Use leaflet to map the Twitter data that you collected in Unit 1 about breakfast, lunch, or dinner.