cvd_grid()
to test your plotsOkabe-Ito Scale. (Okabe, M. and K. Ito, 2008 “Color Universal Design (CUD): How to make Figures and Presentations That Are Friendly To Colorblind People”)
Smaller parts contribute to a larger whole.
Like code built of functions (or a lego house made of smaller pieces).
data.frame
of data to plotmapping = aes()
.geom_*()
and stat_*()
functions.Example: Bullet Graphs
regions_expand <- expand_grid(
regions = regions,
category = bullet_data$category) |>
unnest(regions)
g <- bullet_data |>
ggplot(aes(y = category)) +
geom_col(data = regions_expand,
aes(x = value, fill = label, y = category),
position = position_identity(),
width = 0.6) +
geom_col(aes(x = current), width = 0.2, fill = "black") +
geom_point(aes(x = target), pch = 18, size = 14, colour = palette_OkabeIto[2]) +
scale_fill_manual(
values = list(
"Poor" = "grey40",
"Adequate" = "grey60",
"Good" = "grey90"
)
) +
theme_minimal() +
theme(legend.position = "none")
gapminder |>
group_by(continent, year) |>
summarise(pop = sum(pop)) |>
mutate(label = if_else(year == max(year),
continent,
"")) |>
ggplot(aes(x = year,
y = pop,
colour = continent,
label = label)) +
geom_line() +
geom_text(hjust = 0) +
scale_x_continuous(expand = expansion(mult = c(0.1, 0.2))) +
theme(legend.position = "none")
gapminder |>
group_by(continent, year) |>
summarise(pop = sum(pop)) |>
mutate(label = if_else(year == max(year),
continent,
"")) |>
ggplot(aes(x = year,
y = pop,
colour = continent,
label = label)) +
geom_line() +
ggrepel::geom_text_repel(hjust = 0, direction = "y") +
scale_x_continuous(expand = expansion(mult = c(0.1, 0.2))) +
theme(legend.position = "none")
library(ggtext)
library(glue)
ggplot(penguins,
aes(x = bill_length_mm,
y = flipper_length_mm,
colour = species)) +
geom_point() +
scale_colour_OkabeIto() +
labs(title = "Bill length vs Flipper length (mm)",
subtitle = glue("<span style = 'color:{palette_OkabeIto[1]}'>
Adelie</span> penguins tend to be saller,
<span style = 'color:{palette_OkabeIto[2]}'>Chinstrap</span> penguins
have similar flippers,<br>but larger bills.
<span style = 'color:{palette_OkabeIto[3]}'>Gentoos</span> have
larger flippers.")) +
theme(plot.subtitle = element_markdown()) +
theme(legend.position = "none")
https://clauswilke.com/dataviz/
http://albertocairo.com/
https://www.edwardtufte.com/tufte/