This post describes the options offered by the dygraphs
package for interactive time series visualization with R. It shows the different chart types available and how to customize them.
The dygraphs
R library is my favorite tool to plot time series. The chart #316 describes extensively its basic utilisation, notably concerning the required input format. This page aims to describe the chart types that this library offers. Remember you can zoom and hover on every following chart.
Most of the chart types described in this post are called using the dyOptions()
function. For connected scatterplots, use drawPoints = TRUE
. Note that the gallery offers a whole section on connected scatterplot.
# Library
library(dygraphs)
library(xts) # To make the convertion data-frame / xts format
# Create data
data <- data.frame(
time=seq(from=Sys.Date()-40, to=Sys.Date(), by=1 ),
value=runif(41)
)
# Double check time is at the date format
str(data$time)
# Switch to XTS format
data <- xts(x = data$value, order.by = data$time)
# Default = line plot --> See chart #316
# Add points
p <- dygraph(data) %>%
dyOptions( drawPoints = TRUE, pointSize = 4 )
p
# save the widget
# library(htmlwidgets)
# saveWidget(p, file=paste0( getwd(), "/HtmlWidget/dygraphs317-1.html"))
Area chart are built thanks to the fillGraph = TRUE
option. See the area chart section of the gallery.
p <- dygraph(data) %>%
dyOptions( fillGraph=TRUE )
p
# saveWidget(p, file=paste0( getwd(), "/HtmlWidget/dygraphs317-2.html"))
The step chart is made using the .. stepPlot
option! Use it in conjunction with fillGraph
to fill the area below the curve.
p <- dygraph(data) %>%
dyOptions( stepPlot=TRUE, fillGraph=TRUE)
p
# saveWidget(p, file=paste0( getwd(), "/HtmlWidget/dygraphs317-3.html"))
Called using the stemPlot
option. See the lollipop plot section of the gallery for more.
p <- dygraph(data) %>%
dyOptions( stemPlot=TRUE)
p
# saveWidget(p, file=paste0( getwd(), "/HtmlWidget/dygraphs317-4.html"))
The candlestick chart represents 4 series and is widely used in finance. dygraphs
offers the dyCandlestick()
function that allows to build them in minutes.
# Create data (needs 4 data points per date stamp)
trend <- sin(seq(1,41))+runif(41)
data <- data.frame(
time=seq(from=Sys.Date()-40, to=Sys.Date(), by=1 ),
value1=trend,
value2=trend+rnorm(41),
value3=trend+rnorm(41),
value4=trend+rnorm(41)
)
# switch to xts format
data <- xts(x = data[,-1], order.by = data$time)
# Plot it
p <- dygraph(data) %>%
dyCandlestick()
p
# saveWidget(p, file=paste0( getwd(), "/HtmlWidget/dygraphs317-5.html"))
This is very handy to represent confidence interval around your time series. Don with dySeries()
that takes 3 columns as input: trend and upper and lower limits of the confidence interval.
# Create data
trend <- sin(seq(1,41))+runif(41)
data <- data.frame(
time=seq(from=Sys.Date()-40, to=Sys.Date(), by=1 ),
trend=trend,
max=trend+abs(rnorm(41)),
min=trend-abs(rnorm(41, sd=1))
)
# switch to xts format
data <- xts(x = data[,-1], order.by = data$time)
# Plot
p <- dygraph(data) %>%
dySeries(c("min", "trend", "max"))
p
# saveWidget(p, file=paste0( getwd(), "/HtmlWidget/dygraphs317-6.html"))


title = "New Events"
url = "/new-events"
layout = "default"
is_hidden = 0
[blogPosts]
pageNumber = "{{ :page }}"
categoryFilter = "news"
postsPerPage = 10
noPostsMessage = "No posts found"
sortOrder = "published_at desc"
categoryPage = 404
postPage = "single-news-post"
[campaignrUpcoming]
sorting = "checked"
evtNumber = 100
eventPage = "single-news-post"
eventSlug = ":slug"
==


Do you want to learn digital marketing from the best and kickstart your career in a booming industry?
Digital Consultant Intern
Company description
U-digitalhub is an easy-to-use, intelligent advertising platform that fully automates the creation and management of online ad campaigns for SMB’s. The startup was founded by a team of Digital marketers, software developers and data scientists. We work directly with the offices of Google in Nigeria to develop an impactful tool and help SMB’s around the world grow through cost-effective online marketing solutions.
Job description
U-digitalhub offers you the possibility to complete an internship in Digital Marketing focusing on SEA & Social Media’s within a dynamic start-up.
Searched Profile
We offer
An exciting internship in our offices at Abuja (Nigeria) focusing on Search Engine Advertising & Social Media’s, within a dynamic and fast growing start-up. You will have the opportunity to get yourself involved in interesting projects and show your creativity.
You’ll learn a lot about digital marketing in general and most importantly have fun within the team :)
If interested, please send your resume to<EMAIL_ADDRESS>© All rights reserved, U-digitalhub.