tw_leaflet: Creates a leaflet map

Description Usage Arguments Details Value Author(s) Examples

View source: R/maps.R

Description

This function works as a wrapper of the leaflet function, creating a map with circles which sizes are set by the number of observations in those coordinates.

Usage

1
2
3
tw_leaflet(dat, coordinates = NULL, popup = NULL, lat = NULL,
  lng = NULL, radii = ~sqrt(n) * 5000, weight = 1,
  cluster.method = "centroid", nclusters = min(c(50, nrow(dat)%/%3)), ...)

Arguments

dat

A twitter dataset (with coordinates)

coordinates

Name of the coordinates variable (see details)

popup

Name of the grouping variable (for example, screen_name)

lat

Name of the latitude variable

lng

Name of the longitude variable

radii

Formula to compute the radious of the circles

weight

Thickness of the circles' borders

cluster.method

Clustering method (see hclust())

nclusters

Max number of clusters to include

...

Further arguments to be passed to addCircles()

Details

The coordinates must be in the format of longitude:latitude (as the twitter API returns).

In order to improve visualization, the function performs Hierarchical Clustering via hclust() (from the stats package), grouping observations by geo coordinates. For each cluster, the final lat/lng coords are defined as the mean within the cluster.

In the case of radii, it is measured in meters (in the map). The n is the number of observations in that cluster.

For performance considerations, it is recommended not to use more than 1,000 observations (Try using a random sample from your data!) as hclust requires computing square matrices.

Value

A map object (see the leaflet() package)

Author(s)

George G. Vega Yon

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Not run: 
# Getting the data
data(senate_tweets)

# using formulas to pass the variables names
tw_leaflet(senate_tweets,~coordinates,~screen_name)
tw_leaflet(senate_tweets,~coordinates)

# Using characters to pass the variables names
tw_leaflet(senate_tweets,'coordinates','screen_name')
tw_leaflet(senate_tweets,'coordinates')

# Aggregating until get only 3 big groups
tw_leaflet(senate_tweets,'coordinates', nclusters=3)

## End(Not run)

gvegayon/twitterreport documentation built on May 17, 2019, 9:30 a.m.