The code below makes a dygraph from an object named all that has the names "ldeaths", "p.lwr", "p.fit", "p.upr".
Instead of making plot(all)
in your report below, you'd like to make a dygraph from your object named all that has the names "x", "lower", "fitted", "upper"
Can you do it? Replace plot(all)
below with your dygraph code.
# loads dygraph library library(dygraphs) # preprocesses data (ignore this part: # we've already preprocessed our data in the report below) hw <- HoltWinters(ldeaths) p <- predict(hw, n.ahead = 36, prediction.interval = TRUE) all <- cbind(ldeaths, p) # builds a plot with the title "Deaths from..." dygraph(all, "Deaths from Lung Disease (UK)") %>% # changes the "ldeaths" label" to "Actual" dySeries("ldeaths", label = "Actual") %>% # combines the three prediction lines into a single line # that is named "Predicted" and has a confidence band dySeries(c("p.lwr", "p.fit", "p.upr"), label = "Predicted") %>% # adds a range selector beneath the graph dyRangeSelector()
library(reportsWS) library(forecast) # Select name and gender name <- "Gillian" # Always capitalize sex <- "F" # or "M" names <- get_babyname(name, sex) # Create time series and forecast nbirths <- ts(names$n, start = 1880) mod <- auto.arima(nbirths) pred <- forecast(mod, h = 12) # 12 for 2025
Since 1880, r sum(nbirths, na.rm = TRUE)
children have been named r name
. The graph below breaks this number down by year showing the number of children named r name
as a time series.
# Make plot title <- paste0("Number of children named ", name) all <- bind_as_xts(nbirths, pred) plot(all, main = title)
We modeled this time series with an r trim_whitespace(pred$method)
model to predict the number of children that will be given the name r name
in 2025.
knitr::kable(data.frame( method = trim_whitespace(pred$method), predicted_2025 = round(xts::last(pred$mean))), "markdown")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.