2020-12-02 15:50:03 +01:00
|
|
|
% Generated by roxygen2: do not edit by hand
|
|
|
|
% Please edit documentation in R/facets.R
|
2021-01-04 17:10:29 +01:00
|
|
|
\name{apex-facets}
|
|
|
|
\alias{apex-facets}
|
2020-12-02 15:50:03 +01:00
|
|
|
\alias{ax_facet_wrap}
|
2021-01-04 17:10:29 +01:00
|
|
|
\alias{ax_facet_grid}
|
2020-12-02 15:50:03 +01:00
|
|
|
\title{Facet wrap for ApexCharts}
|
|
|
|
\usage{
|
2020-12-03 10:33:20 +01:00
|
|
|
ax_facet_wrap(
|
|
|
|
ax,
|
2020-12-04 18:00:04 +01:00
|
|
|
facets,
|
2020-12-03 10:33:20 +01:00
|
|
|
nrow = NULL,
|
|
|
|
ncol = NULL,
|
2020-12-03 17:31:04 +01:00
|
|
|
scales = c("fixed", "free", "free_y", "free_x"),
|
2020-12-03 10:33:20 +01:00
|
|
|
labeller = label_value,
|
|
|
|
chart_height = "300px"
|
|
|
|
)
|
2021-01-04 17:10:29 +01:00
|
|
|
|
|
|
|
ax_facet_grid(
|
|
|
|
ax,
|
|
|
|
rows = NULL,
|
|
|
|
cols = NULL,
|
|
|
|
scales = c("fixed", "free", "free_y", "free_x"),
|
|
|
|
labeller = label_value,
|
|
|
|
chart_height = "300px"
|
|
|
|
)
|
2020-12-02 15:50:03 +01:00
|
|
|
}
|
|
|
|
\arguments{
|
|
|
|
\item{ax}{An \code{apexcharts} \code{htmlwidget} object.}
|
|
|
|
|
2020-12-04 18:00:04 +01:00
|
|
|
\item{facets}{Variable(s) to use for facetting, wrapped in \code{vars(...)}.}
|
2020-12-02 15:50:03 +01:00
|
|
|
|
|
|
|
\item{nrow, ncol}{Number of row and column in output matrix.}
|
|
|
|
|
2020-12-08 16:22:24 +01:00
|
|
|
\item{scales}{Should scales be fixed (\code{"fixed"}, the default),
|
|
|
|
free (\code{"free"}), or free in one dimension (\code{"free_x"}, \code{"free_y"})?}
|
|
|
|
|
|
|
|
\item{labeller}{A function with one argument containing for each facet the value of the faceting variable.}
|
|
|
|
|
2020-12-02 15:50:03 +01:00
|
|
|
\item{chart_height}{Individual chart height.}
|
2021-01-04 17:10:29 +01:00
|
|
|
|
|
|
|
\item{rows, cols}{A set of variables or expressions quoted by vars() and defining faceting groups on the rows or columns dimension.}
|
2020-12-02 15:50:03 +01:00
|
|
|
}
|
|
|
|
\value{
|
|
|
|
An \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
}
|
|
|
|
\description{
|
|
|
|
Facet wrap for ApexCharts
|
2020-12-08 16:22:24 +01:00
|
|
|
}
|
|
|
|
\examples{
|
2021-01-05 15:08:13 +01:00
|
|
|
### Wrap --------
|
2020-12-08 16:22:24 +01:00
|
|
|
|
2021-04-28 09:01:33 +02:00
|
|
|
if (interactive()) {
|
|
|
|
library(apexcharter)
|
2020-12-08 16:22:24 +01:00
|
|
|
|
2021-04-28 09:01:33 +02:00
|
|
|
# Scatter ----
|
2020-12-08 16:22:24 +01:00
|
|
|
|
2021-04-28 09:01:33 +02:00
|
|
|
data("mpg", package = "ggplot2")
|
|
|
|
|
|
|
|
# Create facets
|
|
|
|
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
|
|
|
ax_facet_wrap(vars(drv))
|
|
|
|
|
|
|
|
# Change number of columns
|
|
|
|
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
|
|
|
ax_facet_wrap(vars(drv), ncol = 2)
|
|
|
|
|
|
|
|
# Free axis
|
|
|
|
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
|
|
|
ax_facet_wrap(vars(drv), ncol = 2, scales = "free")
|
|
|
|
|
|
|
|
# labels
|
|
|
|
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
|
|
|
ax_facet_wrap(
|
|
|
|
vars(drv), ncol = 2,
|
|
|
|
labeller = function(x) {
|
|
|
|
switch(
|
|
|
|
x,
|
|
|
|
"f" = "front-wheel drive",
|
|
|
|
"r" = "rear wheel drive",
|
|
|
|
"4" = "4wd"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
# Title and subtitle are treated as global
|
|
|
|
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
|
|
|
ax_labs(
|
|
|
|
title = "Facet wrap example",
|
|
|
|
subtitle = "mpg data from ggplot2"
|
|
|
|
) \%>\%
|
|
|
|
ax_facet_wrap(vars(drv), ncol = 2)
|
|
|
|
|
|
|
|
|
|
|
|
# Multiple variables
|
|
|
|
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
|
|
|
ax_facet_wrap(vars(year, drv))
|
|
|
|
|
|
|
|
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
|
|
|
ax_facet_wrap(vars(year, drv), ncol = 2, nrow = 3)
|
|
|
|
|
|
|
|
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
|
|
|
ax_chart(toolbar = list(show = FALSE)) \%>\%
|
|
|
|
ax_facet_wrap(
|
|
|
|
vars(year, drv),
|
|
|
|
labeller = function(x) {
|
|
|
|
paste(x, collapse = " / ")
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Lines ----
|
|
|
|
|
|
|
|
data("unhcr_ts")
|
|
|
|
refugees <- unhcr_ts \%>\%
|
|
|
|
subset(population_type == "Refugees (incl. refugee-like situations)") \%>\%
|
|
|
|
transform(date = as.Date(paste0(year, "-01-01")))
|
|
|
|
|
|
|
|
|
|
|
|
apex(refugees, aes(date, n), type = "line") \%>\%
|
|
|
|
ax_yaxis(tickAmount = 5) \%>\%
|
|
|
|
ax_facet_wrap(vars(continent_origin))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Free y-axis and synchronize
|
|
|
|
apex(refugees, aes(date, n), type = "line", synchronize = "my-id") \%>\%
|
|
|
|
ax_yaxis(tickAmount = 5) \%>\%
|
|
|
|
ax_xaxis(tooltip = list(enabled = FALSE)) \%>\%
|
|
|
|
ax_tooltip(x = list(format = "yyyy")) \%>\%
|
|
|
|
ax_facet_wrap(vars(continent_origin), scales = "free_y")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Bars ----
|
|
|
|
|
|
|
|
data("unhcr_ts")
|
|
|
|
refugees <- unhcr_ts \%>\%
|
|
|
|
subset(year == 2017)
|
|
|
|
|
|
|
|
apex(refugees, aes(continent_origin, n), type = "column") \%>\%
|
|
|
|
ax_yaxis(
|
|
|
|
labels = list(
|
|
|
|
formatter = format_num("~s")
|
|
|
|
),
|
|
|
|
tickAmount = 5
|
|
|
|
) \%>\%
|
|
|
|
ax_facet_wrap(vars(population_type), ncol = 2)
|
|
|
|
|
|
|
|
}
|
2021-01-05 15:08:13 +01:00
|
|
|
|
|
|
|
### Grid --------
|
2021-04-28 09:01:33 +02:00
|
|
|
if (interactive()) {
|
|
|
|
library(apexcharter)
|
|
|
|
|
|
|
|
# Scatter ----
|
|
|
|
|
|
|
|
data("mpg", package = "ggplot2")
|
|
|
|
|
|
|
|
# Only rows
|
|
|
|
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
|
|
|
ax_facet_grid(rows = vars(drv), chart_height = "200px")
|
|
|
|
|
|
|
|
# Only cols
|
|
|
|
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
|
|
|
ax_facet_grid(cols = vars(year))
|
|
|
|
|
|
|
|
# Rows and Cols
|
|
|
|
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
|
|
|
ax_facet_grid(rows = vars(drv), cols = vars(year))
|
|
|
|
|
|
|
|
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
|
|
|
ax_chart(toolbar = list(show = FALSE)) \%>\%
|
|
|
|
ax_facet_grid(vars(drv), vars(cyl))
|
|
|
|
|
|
|
|
|
|
|
|
# Labels
|
|
|
|
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
|
|
|
ax_facet_grid(
|
|
|
|
vars(drv),
|
|
|
|
labeller = function(x) {
|
|
|
|
switch(
|
|
|
|
x,
|
|
|
|
"f" = "front-wheel drive",
|
|
|
|
"r" = "rear wheel drive",
|
|
|
|
"4" = "4wd"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Title and subtitle are treated as global
|
|
|
|
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
|
|
|
|
ax_labs(
|
|
|
|
title = "Facet grid example",
|
|
|
|
subtitle = "mpg data from ggplot2"
|
|
|
|
) \%>\%
|
|
|
|
ax_facet_grid(rows = vars(drv), cols = vars(year))
|
|
|
|
|
|
|
|
}
|
2020-12-02 15:50:03 +01:00
|
|
|
}
|