How To Plot With Dygraphs: Exercises

May 18, 2018

(This article was first published on R-exercises, and kindly contributed to R-bloggers)


The dygraphs package is an R interface to the dygraphs JavaScript charting library. It provides rich facilities for charting time-series data in R, including:

1. Automatically plots xts time-series objects (or any object convertible to xts.)

2. Highly configurable axis and series display (including optional second Y-axis.)

3. Rich interactive features, including zoom/pan and series/point highlighting.

4. Display upper/lower bars (ex. prediction intervals) around the series.

5. Various graph overlays, including shaded regions, event lines, and point annotations.

6. Use at the R console, just like conventional R plots (via RStudio Viewer.)

7. Seamless embedding within R Markdown documents and Shiny web applications.

Before proceeding, please follow our short tutorial.

Look at the examples given and try to understand the logic behind them. Then, try to solve the exercises below by using R without looking at the answers. Then, check the solutions to check your answers.

Exercise 1

Unite the two time series data-sets mdeaths and fdeaths and create a time-series dygraph of the new data-set.

Exercise 2

Insert a date range selector into the dygraph you just created.

Exercise 3

Change the label names of “mdeaths” and “fdeaths” to “Male” and “Female.”

Exercise 4

Make the graph stacked.

Exercise 5

Set the date range selector height to 20.

Exercise 6

Add a main title to your graph.

Exercise 7

Use the tutorial’s predicted data-set to create a dygraph of “lwr”, “fit”, and “upr”, but display the label as the summary of them.

Exercise 8

Set the colors to red.

Exercise 9

Remove the x-axis grid lines from your graph.

Exercise 10

Remove the y-axis grid lines from your graph.

To leave a comment for the author, please follow the link and comment on their blog: R-exercises. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)