library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# We first make some random data
stacked_data <- tibble::tibble(
Agegroup = rep(c("0-9", "10-19", "20-29", "30-39"), each = 3),
Sex = factor(rep(c("Man", "Vrouw", "Onbekend"), times = 4),
levels = c("Man", "Vrouw", "Onbekend")),
n = c(10, 14, 2, 15, 17, 1, 23, 18, 0, 9, 11, 3)
)
# Then we make the basic plotly plot
sex_colors <- c(
"Man" = ro_color("hemelblauw"),
"Vrouw" = ro_color("robijnrood"),
"Onbekend" = ro_color("donkergeel")
)
fig <- plot_ly(
data = stacked_data,
x = ~Agegroup,
y = ~n,
type = "bar",
color = ~Sex,
colors = sex_colors,
text = ~paste0(
"Leeftijdsgroep: <b>", Agegroup, "</b>",
"<br>Geslacht: <b>", Sex, "</b>",
"<br>Aantal cases: <b>",
format(round(n, 0), big.mark = ".", decimal.mark = ",", scientific = FALSE), "</b>"
),
hovertext = ~paste0(
"Leeftijdsgroep: <b>", Agegroup, "</b>",
"<br>Geslacht: <b>", Sex, "</b>",
"<br>Aantal cases: <b>",
format(round(n, 0), big.mark = ".", decimal.mark = ",", scientific = FALSE), "</b>"
),
textposition = "none",
hoverinfo = "text"
)
# And apply the Rijksoverheid / RIVM theme, and accesibility features
fig <- ro_ply_standard(fig,
type = "bargraph",
barmode = "stack",
y_data = stacked_data |> group_by(Agegroup) |> summarise(n_total = sum(n)) |> pull(n_total),
title = "COVID-19 cases per leeftijdsgroep en geslacht",
x_label = "Leeftijdsgroep",
y_label = "Aantal cases"
)
## ! Can't find the `base_family` = "RijksoverheidSansWebText" in installed fonts,
## and neither fall-back fonts, "Verdana" and "Arial", are installed.
## ℹ Falling back to "URW Gothic", the first font found on this system. Check
## installed system fonts with `systemfonts::system_fonts()`.
## ! Can't find the `base_family` = "RijksoverheidSansWebText" in installed fonts,
## and neither fall-back fonts, "Verdana" and "Arial", are installed.
## ℹ Falling back to "URW Gothic", the first font found on this system. Check
## installed system fonts with `systemfonts::system_fonts()`.
fig