facet_grid: labeller

This commit is contained in:
pvictor 2021-01-05 12:14:48 +01:00
parent bdf6e19597
commit 730d6651a0
2 changed files with 26 additions and 2 deletions

View File

@ -263,14 +263,22 @@ build_facet_tag <- function(x) {
for (i in seq_along(facets$label_row)) {
content <- append(
x = content,
values = tagList(tags$div(class = "apexcharter-facet-row-label", facets$label_row[i])),
values = tagList(tags$div(
class = "apexcharter-facet-row-label",
x$x$facet$labeller(facets$label_row[i])
)),
after = ((facets$ncol %||% 1 + 1) * i) - 1
)
}
}
if (!is.null(facets$ncol)) {
content <- tagList(
lapply(facets$label_col, FUN = tags$div, class = "apexcharter-facet-col-label"),
lapply(
X = facets$label_col,
FUN = function(x) {
tags$div(x$x$facet$labeller(x), class = "apexcharter-facet-col-label")
}
),
if (!is.null(facets$nrow)) tags$div(),
content
)

View File

@ -18,3 +18,19 @@ apex(mpg, aes(displ, cty), type = "scatter") %>%
apex(mpg, aes(displ, cty), type = "scatter") %>%
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"
)
}
)