In this session you will explore several ways to generate dynamic and interactive data displays. These include making maps and graphs that you can pan/zoom, select features for more information, and interact with in other ways. The most common output format is HTML, which can easily be embedded in a website (such as your final project!).
library(tidyverse)
library(htmlwidgets)
library(widgetframe)
If you don’t have the packages above, install them in the package
manager or by running install.packages("widgetframe")
,
etc.
Make a dygraph of recent daily temperature data from Buffalo, NY.
First use the following code to download recent daily weather data for UB.
library(xts)
library(dygraphs)
library(openmeteo)
d<- weather_history(c(43.00923265935055, -78.78494250958327),start = "2023-01-01",end=today(),
daily=list("temperature_2m_max","temperature_2m_min","precipitation_sum")) %>%
mutate(daily_temperature_2m_mean=(daily_temperature_2m_max+daily_temperature_2m_min)/2)
Remaining steps:
d
. into an xts
time series object
using xts()
. By default, dygraph will plot all non-date
columns in the table so you may need to use select()
first
to subset only the columns you need. You will need to specify which
columns have the data you want
(e.g. d$daily_temperature_2m_max
) and which column has the
date with order.by=d$date
. See ?xts
for
help.main="Daily Maximum Temperature in Buffalo, NY"
dygraph()
to draw the plot. If you want to do the
ribbon plot below (showing min, max, and mean temps), you will need to
use dySeries()
as well. Check out the help and examples to
see how that’s used.dyRangeSelector()
with a dateWindow
of c("2023-01-01", "2024-10-31")
At a minimum, your final graph should look something like this:
What other visualizations can you make with these data?