This vignette covers the
customization options available across dashboardr visualization
functions. We use General Social Survey (GSS) data from the
gssr package to demonstrate each feature.
library(gssr)
data(gss_all)
gss <- gss_all %>%
filter(year >= 2000) %>%
select(year, sex, race, degree, happy, rincome, age, marital) %>%
mutate(
sex = haven::as_factor(sex),
race = haven::as_factor(race),
degree = haven::as_factor(degree),
happy = haven::as_factor(happy),
rincome = haven::as_factor(rincome),
marital = haven::as_factor(marital)
) %>%
filter(!is.na(sex), !is.na(race), !is.na(degree))Use color_palette to control the colors used in any
visualization. You can pass:
The tooltip() helper gives you full control over hover
information.
Use {placeholders} to insert dynamic values:
Control the legend with legend_position:
Toggle data labels with data_labels_enabled and control
decimal precision with label_decimals:
Customize axis labels with x_label and
y_label:
Add error bars to bar charts with error_bars. Options
include "se" (standard error), "sd" (standard
deviation), and "ci" (confidence interval):
Flip the orientation with horizontal = TRUE:
Sort bars by value rather than category order:
Use x_order to specify a custom display order:
Include NA values in charts using
include_na and na_label:
Use theme functions to apply consistent styling across a dashboard. These are applied at the dashboard level:
dashboard <- create_dashboard(
title = "GSS Analysis",
data = gss
) %>%
apply_theme(theme_modern(
font_family = "Inter"
))Available built-in themes:
theme_modern() — Clean modern look with Inter fonttheme_clean() — Minimal stylingtheme_academic() — Academic/research styledashboardr supports multiple rendering backends. Pass
backend to any viz function:
See vignette("chart-backends") for a full comparison of
available backends and their capabilities.
Most options can be combined freely:
viz_bar(
data = gss,
x_var = "degree",
group_var = "sex",
bar_type = "percent",
title = "Education by Gender",
subtitle = "GSS 2000-2021",
x_label = "Highest Degree",
y_label = "Percentage",
horizontal = TRUE,
color_palette = c("Male" = "#4E79A7", "Female" = "#E15759"),
legend_position = "bottom",
label_decimals = 0,
tooltip = tooltip(suffix = "%", shared = TRUE)
)