Calendar Plots With ggplot2
[This article was first published on Albert Rapp, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(reactable)
counts <- palmerpenguins::penguins |>
filter(!is.na(sex)) |>
dplyr::count(species, island, sex) |>
pivot_wider(
names_from = sex,
values_from = n
)
counts |>
reactable(
groupBy = 'species',
columns = list(
species = colDef(
footer = 'Total',
footerStyle = 'font-weight: 600;'
),
island = colDef(
filterable = TRUE
),
female = colDef(
aggregate = 'sum',
footer = function(values, col_names) {
sum(values)
}
),
male = colDef(
aggregate = 'sum',
footer = function(values, col_names) {
sum(values)
}
)
)
)
counts |>
reactable(
groupBy = 'species',
defaultExpanded = TRUE,
columns = list(
species = colDef(
footer = 'Total',
footerStyle = 'font-weight: 600;'
),
island = colDef(
filterable = TRUE
),
female = colDef(
aggregate = 'sum',
footer = JS("function(column, state) {
let total = 0;
state.sortedData.forEach(function(row) {
total += row[column.id];
});
return total;
}")
),
male = colDef(
aggregate = 'sum',
footer = JS("function(column, state) {
let total = 0;
state.sortedData.forEach(function(row) {
total += row[column.id];
});
return total;
}")
)
)
)
To leave a comment for the author, please follow the link and comment on their blog: Albert Rapp.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.