dygraphs
packagexts
library(dygraphs)
dygraph(nhtemp, main = "New Haven Temperatures") %>%
dyRangeSelector(dateWindow = c("1920-01-01", "1960-01-01"))
xts
Datasets must either be time series data or numeric data. For time series, this must be an xts
object or an object which is convertible to xts
(such as zoo
). For numeric data, this must be a named list or data frame, where the first element/column provides x-axis values and all subsequent elements/columns provide one or more series of y-values.
We use the quarterly time series of the number of Australian residents.
head(austres)
## [1] 13067.3 13130.5 13198.4 13254.2 13303.7 13353.9
library(xts)
## Le chargement a nécessité le package : zoo
##
## Attachement du package : 'zoo'
## Les objets suivants sont masqués depuis 'package:base':
##
## as.Date, as.Date.numeric
# Convert austres into an xts object
<- as.xts(austres)
au head(au, 5)
## [,1]
## 1971 Q2 13067.3
## 1971 Q3 13130.5
## 1971 Q4 13198.4
## 1972 Q1 13254.2
## 1972 Q2 13303.7
library(dygraphs)
dygraph(au, main = "Number of Australian residents") %>%
dyRangeSelector(dateWindow = c("1972-01-01", "1990-01-01"))
head(sunspots)
## [1] 58.0 62.6 70.0 55.7 85.0 83.5
library(xts)
# Convert sunspots to xts
<- as.xts(sunspots)
sunspots_xts head(sunspots_xts, 5)
## [,1]
## jan 1749 58.0
## fév 1749 62.6
## mar 1749 70.0
## avr 1749 55.7
## mai 1749 85.0
library(dygraphs)
dygraph(sunspots_xts, main = "Sunspots") %>%
dyRangeSelector(dateWindow = c("1800-01-01", "1830-01-01"))
<- cbind(ldeaths, mdeaths, fdeaths)
lungDeaths
head(lungDeaths, 3)
## ldeaths mdeaths fdeaths
## [1,] 3035 2134 901
## [2,] 2552 1863 689
## [3,] 2704 1877 827
library(dygraphs)
dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
dyOptions(colors = c('red', 'blue', 'orange'))
dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
dyOptions(colors = RColorBrewer::brewer.pal(3, "Set2"))
library(dygraphs)
# Step plots
dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
dyOptions(colors = RColorBrewer::brewer.pal(3, "Set2")) %>%
dyOptions(stepPlot = TRUE)
# dyOptions(fillGraph = TRUE, fillAlpha = 0.4)
# dyOptions(drawPoints = TRUE, pointSize = 2)
# dyOptions(drawPoints = TRUE, pointSize = 5, pointShape = "triangle")
# triangle, square, diamond, pentagon, hexagon, circle, star, plus, ex
library(dygraphs)
dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
dySeries("ldeaths", drawPoints = FALSE, color = "red") %>%
dySeries("mdeaths", drawPoints = TRUE, color = "blue") %>%
dySeries("fdeaths", stepPlot = TRUE, fillGraph = TRUE, color = "orange")
# dySeries("ldeaths", strokeWidth = 2, strokePattern = "dashed")
# dyGroup(c("mdeaths", "ldeaths"), drawPoints = TRUE, color = c("blue", "green"))