Some strategies for interactively visualizing spatial data.
These are optional notes. The reading does not cover interactivity in spatial data contexts, and there will be no problems in this class related to interactive spatial data visualization. However, these notes may be useful if your project involves interaction with spatial data.
In vega-lite
, vector data can be visualized using vl.markGeoshape
. Any fields contained within the vector dataset can be visually encoded in the marks. This is analogous to geom_sf
in ggplot2.
.markGeoshape({fill: "#e0e0e0", stroke: "#f7f7f7", strokeWidth: 1})
vl.data(vector_data) // contains the vector data boundaries
.project(vl.projection('albersUsa'))
.render()
robservable("@krisrs1128/minimal-geoshape", 3, height = 300)
robservable("@chanwutk/happiness-of-each-country", 6, height = 750)
The second, by Alissa Chen, shows how the amount of daylight varies across cities, depending on time of the year. Brushing over the time series filters the data that are used to determine the circle widths (the little suns) on top of the map.
robservable("@alchan/whats-the-average-amount-of-sunlight-in-a-city-over-a-short-te", 3, height = 730)
robservable("@krisrs1128/geojson-mouseover", 7)
leaflet
package in R can be useful. In the code block below, addTiles
fetches the background map. addCircles
overlays the new vector features on top of the map. It’s worth noting that the vector features were created automatically – there was no need to create or read in any type of sf
object.cities <- read_csv("https://uwmadison.box.com/shared/static/j98anvdoasfb1h651qxzrow2ua45oap1.csv")
leaflet(cities) %>%
addTiles() %>%
addCircles(
lng = ~Long,
lat = ~Lat,
radius = ~sqrt(Pop) * 30
)