The objective of this vignette is to show how to quickly build data visualizations with the ApexCharts JavaScript library, as well as to give an overview of the different graphics available.
Data used are from ggplot2
package, data manipulation will be done with the dplyr
package.
Simple bar charts can be created with:
data("mpg")
n_manufac <- count(mpg, manufacturer)
apex(data = n_manufac, type = "column", mapping = aes(x = manufacturer, y = n))
Flipping coordinates can be done by using type = "bar"
:
To create a dodge bar charts, use aesthetic fill
:
n_manufac_year <- count(mpg, manufacturer, year)
apex(data = n_manufac_year, type = "column", mapping = aes(x = manufacturer, y = n, fill = year))
For stacked bar charts, specify option stacked
in ax_chart
:
Simple line charts can be created with (works with character
, Date
or POSIXct
):
data("economics")
economics <- tail(economics, 100)
apex(data = economics, type = "line", mapping = aes(x = date, y = uempmed))
To represent several lines, use a data.frame
in long format and the group
aesthetic:
data("economics_long")
economics_long <- economics_long %>%
group_by(variable) %>%
slice((n()-100):n())
apex(data = economics_long, type = "line", mapping = aes(x = date, y = value01, group = variable)) %>%
ax_yaxis(decimalsInFloat = 2) # number of decimals to keep
Create area charts with type = "area"
:
Simple bar charts can be created with:
Color points according to a third variable:
And change point size using z
aesthetics:
Simple pie charts can be created with:
Simple radial charts can be created with (here we pass values directly in aes
, but you can use a data.frame
) :
Multi radial chart (more than one value):
Simple radar charts can be created with:
mtcars$model <- rownames(mtcars)
apex(data = head(mtcars), type = "radar", mapping = aes(x = model, y = qsec))
With a grouping variable:
# extremely complicated reshaping
new_mtcars <- reshape(
data = head(mtcars),
idvar = "model",
varying = list(c("drat", "wt")),
times = c("drat", "wt"),
direction = "long",
v.names = "value",
drop = c("mpg", "cyl", "hp", "dist", "qsec", "vs", "am", "gear", "carb")
)
apex(data = new_mtcars, type = "radar", mapping = aes(x = model, y = value, group = time))
Create heatmap with :
Create a candlestick chart with: