X Tutup
#' --- #' title: Dynamic HTML graph of Daily Temperatures #' subtitle: Using DyGraph library. #' week: 12 #' type: Case Study #' reading: #' - Explore the [DyGraphs webpage](http://rstudio.github.io/dygraphs/) #' tasks: #' - Download daily weather data for Buffalo, NY using an API #' - Generate a dynamic html visualization of the timeseries. #' - Save the graph to your project folder using Export->Save as Webpage #' --- #' #' #' #' # Reading #' #' #' #' # Tasks #' #' #' ## Background #' 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!). #' ## ----cache=F, message=F,warning=FALSE------------------------------------ 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. #' #' # Objective #' > Make a dygraph of recent daily maximum temperature data from Buffalo, NY. #' #' ## Detailed Steps #' #' First use the following code to download the daily weather data. #' ## ---- messages=F, warning=F, results=F----------------------------------- library(rnoaa) library(xts) library(dygraphs) d=meteo_tidy_ghcnd("USW00014733", date_min = "2016-01-01", var = c("TMAX"), keep_flags=T) d$date=as.Date(d$date) #' #' Remaining steps: #' #' 1. Convert `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. #' 2. Use `dygraph()` to draw the plot #' 3. Set the title of the dygraph to be `main="Daily Maximum Temperature in Buffalo, NY"` #' 3. Add a `dyRangeSelector()` with a `dateWindow` of `c("2017-01-01", "2017-12-31")` #' #' #' ## Output #' #' Your final graph should look something like this: #'
X Tutup