Course: VISUAL ANALYTICS FOR POLICY AND MANAGEMENT

Prof. José Manuel Magallanes, PhD

  • Visiting Professor of Computational Policy at Evans School of Public Policy and Governance, and eScience Institute Senior Data Science Fellow, University of Washington.
  • Professor of Government and Political Methodology, Pontificia Universidad Católica del Perú.

Session 7: Spatial Data - Interactive


Making interactive plots is a good option when you are planing a visual in a webpage. Let’s get the data:

## Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1

The data above is a map that includes a data frame. Let me use the data first for a simple scatter plot:

Now let’s make the interactive version:

We can try a map now:

It will be used by plotly:

A very interesting package is leaflet which will allow for more interesting options:

Let me install and load the necessary packages:

Let’s see how to color our numerical data:

  1. Decide the amount of groups:

  2. Decide the color palette (I chose one from here):

  3. Compute the bins

## [1] 1.320 3.238 5.056 6.384 7.644 9.810
  1. Create the palette function:

  2. Plot!

Let me bring the data set on cities we used before, and turn it into a spatial element:

As this is a spatial object:

As before:

Let’s cluster these data on cities:

Notice the size legend will not look good, so I will drop it now:

Let me prepare a leaflet for this last visual, this time using a categorical palette:

Any basic leaflet map allows interaction, but it is tricky to come back to the original situation. This is how you can do it by adding a button (check icons here:

Let me save the idxcity_sf object, to use in my dashboards.

LEAFLET DASHBOARDS

If you need to plot more than one map, we can try two options:

  1. Using sync from leafsync, where the maps will be synchronized:
  1. Maps will not be synched: