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:
Decide the amount of groups:
Decide the color palette (I chose one from here):
Compute the bins
## [1] 1.320 3.238 5.056 6.384 7.644 9.810
Create the palette function:
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.
If you need to plot more than one map, we can try two options: