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(dplyr)
library(ggplot2)
library(ggmap)
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 maximum temperature data from Buffalo, NY.
First use the following code to download the daily weather data.
library(tidyverse)
library(rnoaa)
library(xts)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## Attaching package: 'xts'
## The following object is masked from 'package:leaflet':
##
## addLegend
## The following objects are masked from 'package:dplyr':
##
## first, last
library(dygraphs)
d=meteo_tidy_ghcnd("USW00014733",
date_min = "2016-01-01",
var = c("TMAX"),
keep_flags=T) %>%
mutate(date=as.Date(date),
tmax=as.numeric(tmax)/10) #Divide the tmax data by 10 to convert to degrees.
## using cached file: ~/Library/Caches/R/noaa_ghcnd/USW00014733.dly
## date created (size, mb): 2022-05-10 12:03:21 (8.568)
## file min/max dates: 1938-05-01 / 2022-05-31
Remaining steps:
d
into an xts
time series object
using xts()
. You will need to specifify which column has
the data (d$tmax
) and order.by=d$date
. See
?xts
for help.dygraph()
to draw the plotmain="Daily Maximum Temperature in Buffalo, NY"
dyRangeSelector()
with a dateWindow
of c("2020-01-01", "2020-10-31")
At a minimum, your final graph should look something like this:
What other visualizations can you make with these data?