machine <- "#061939"
human <- "#e25470"
monochromeR::generate_palette(machine,
blend_colour = human,
n_colours = 3,
view_palette = TRUE)
NHS-R 2022 | Online Workshop | 4th November 2022
š© Cara Thompson
š©āš» Psychology PhD %>%
Analysis of postgraduate medical examinations %>%
Freelance data consultant specialising in dataviz and āenhancedā reproducible outputs
š Helping others maximise the impact of their expertise
Find out more: cararthompson.com/about
To equip you with design tips and coding tricks to enhance the story-telling capabilities of your plots.
A mix of talk, live coding and exercises
R
forā¦To equip you with design tips and coding tricks to enhance the story-telling capabilities of your plots.
A mix of talk, live coding and exercises
The penguins had a baking competition to see which species could make the best banana loaf. Each species was given bananas of a different level of ripeness.
The penguins had a baking competition to see which species could make the best banana loaf. Each species was given bananas of a different level of ripeness.
The Adelie penguins decided to experiment with different quantities of banana in their mix. Each island chose a different quantity.
The Adelie penguins decided to experiment with different quantities of banana in their mix. Each island chose a different quantity.
The penguins also baked their cakes for different amounts of time. Here are the mean durations per species. Which species left their cakes in the oven for longest?
The penguins also baked their cakes for different amounts of time. Here are the mean durations per species. Which species left their cakes in the oven for longest?
Make it easy for the readers to remember what is what.
But my research isnāt about bananas!
package::function()
rather than loading whole libraries (helps us see where everything comes from!)library(tidyverse)
reference-scripts/
to show where we got toWe first letās modify the data, so that we have banana quantities to visualise!
library(tidyverse)
penguins <- palmerpenguins::penguins %>%
mutate(banana_quantity =
case_when(
species == "Adelie" &
island == "Biscoe" ~ 1,
species == "Adelie" &
island == "Dream" ~ 0.6,
species == "Adelie" &
island == "Torgersen" ~ 0,
TRUE ~ 1))
penguins %>%
select(species, island, banana_quantity) %>%
distinct()
# A tibble: 5 x 3
species island banana_quantity
<fct> <fct> <dbl>
1 Adelie Torgersen 0
2 Adelie Biscoe 1
3 Adelie Dream 0.6
4 Gentoo Biscoe 1
5 Chinstrap Dream 1
Ripeness & quantities, baking duration (bill depth), yumminess (bill length)
Ripeness & quantities, baking duration (bill depth), yumminess (bill length)
Ripeness & quantities, baking duration (bill depth), yumminess (bill length)
Ripeness & quantities, baking duration (bill depth), yumminess (bill length)
Ripeness & quantities, baking duration (bill depth), yumminess (bill length)
basic_plot <- ggplot(penguins,
aes(x = bill_depth_mm,
y = bill_length_mm,
colour = species)) +
geom_point(aes(alpha = banana_quantity)) +
labs(title = "Banana loaf tastes best when baked with ripe or over-ripe bananas",
subtitle = "The Palmer Penguins carried out an experiment using bananas of different ripeness.
The Adelie penguins were given unripe bananas, Gentoos were given over-ripe
bananas and Chinstraps were given yellow bananas.
Each penguin was left to choose their own cooking time.",
x = "Baking time",
y = "Yumminess",
caption = "Data from {palmerpenguins}; misused for illustration purposes.") +
scale_alpha(range = c(0.2, 1),
breaks = c(0.1, 0.5, 1)) +
theme_minimal(base_size = 12)
basic_plot
Adelie = Unripe, Chinstrap = Ripe, Gentoo = Over-ripe
The quick fixā¦
ā¦ might be a dangerous shortcut!
ggplot(penguins %>%
# Oh, that should be a factor,
# let me fix that for you!
mutate(species =
factor(species,
levels = c("Chinstrap",
"Gentoo",
"Adelie"))),
aes(x = bill_depth_mm,
y = bill_length_mm,
colour = species)) +
geom_point() +
theme_minimal() +
scale_colour_manual(values = c("#89973d",
"#e8b92f",
"#a45e41"))
Create a named list!
Create a named list!
banana_colours <- list("Adelie" = "#89973d",
"Chinstrap" = "#e8b92f",
"Gentoo" = "#a45e41")
ggplot(penguins %>%
# Oh, that should be a factor,
# let me fix that for you!
mutate(species =
factor(species,
levels = c("Chinstrap",
"Gentoo",
"Adelie"))),
aes(x = bill_depth_mm,
y = bill_length_mm,
colour = species)) +
geom_point() +
theme_minimal() +
scale_colour_manual(values = banana_colours)
Create a named list!
Choosing colours is tricky!
Here are a few starting pointsā¦
Find out more: blog.datawrapper.de/colors-for-data-vis-style-guides/
Weāve done this already!
See you in 15 minutes! š šØ ā
15:00
Say hello to š¦ {ggtext}
Say hello to š¦ {ggtext}
Say hello to š¦ {ggtext}
basic_plot +
scale_colour_manual(values = banana_colours) +
labs(title = paste0(
"Banana loaf tastes best when baked with ",
"<span style=\"color:", banana_colours$Chinstrap,
"\">ripe</span> or <span style=\"color:",
banana_colours$Gentoo, "\">over-ripe</span> bananas")) +
theme(plot.title = ggtext::element_markdown())
When using colour, make sure the text is still readable; use āboldā if needed
basic_plot +
scale_colour_manual(values = banana_colours) +
labs(title = paste0(
"Banana loaf tastes best when baked with ",
"<span style=\"color:", banana_colours$Chinstrap,
"\">**ripe**</span> or <span style=\"color:",
banana_colours$Gentoo, "\">**over-ripe**</span> bananas")) +
theme(plot.title = ggtext::element_markdown())
Find out more: https://www.interaction-design.org/
Two more colours for our palette - Starting from the main banana colour, we go darker for dark text - We then go lighter from there to create a light text colour
dark_text <- monochromeR::generate_palette(
banana_colours$Chinstrap, "go_darker",
n_colours = 2)[2]
light_text <- monochromeR::generate_palette(
dark_text, "go_lighter",
n_colours = 3)[2]
banana_colours <- list("Adelie" = "#89973d",
"Chinstrap" = "#e8b92f",
"Gentoo" = "#a45e41",
"dark_text" = dark_text,
"light_text" = light_text)
monochromeR::view_palette(banana_colours)
Make sure they donāt appear in the legend!
basic_plot +
scale_colour_manual(values = banana_colours,
limits = force) +
labs(title = paste0(
"Banana loaf tastes best when baked with ",
"<span style=\"color:", banana_colours$Chinstrap,
"\">**ripe**</span> or <span style=\"color:",
banana_colours$Gentoo, "\">**over-ripe**</span> bananas")) +
theme(plot.title = ggtext::element_markdown())
Add a base colour and font for text
basic_plot +
scale_colour_manual(values = banana_colours, limits = force) +
labs(title = paste0(
"Banana loaf tastes best when baked with ",
"<span style=\"color:", banana_colours$Chinstrap,
"\">**ripe**</span> or <span style=\"color:",
banana_colours$Gentoo, "\">**over-ripe**</span> bananas")) +
theme(text = element_text(family = "Cabin",
colour = banana_colours$light_text),
plot.title = ggtext::element_markdown())
Override it in the title and change the font and size of the title
basic_plot +
scale_colour_manual(values = banana_colours, limits = force) +
labs(title = paste0(
"Banana loaf tastes best when baked with ",
"<span style=\"color:", banana_colours$Chinstrap,
"\">**ripe**</span> or <span style=\"color:",
banana_colours$Gentoo, "\">**over-ripe**</span> bananas")) +
theme(text = element_text(family = "Cabin",
colour = banana_colours$light_text),
plot.title = ggtext::element_markdown(colour = banana_colours$dark_text))
Shift to ggsave()
to avoid disappointment when rendering output!
Text size changes between the Viewer and the exported plot, dependent on plot size and resolution. Set these before you spend too much time fine-tuning your text!
Add a line<br>
eak where needed!
basic_plot +
scale_colour_manual(values = banana_colours, limits = force) +
labs(title = paste0(
"Banana loaf tastes best when baked with ",
"<span style=\"color:", banana_colours$Chinstrap,
"\">**ripe**</span> or<br><span style=\"color:",
banana_colours$Gentoo, "\">**over-ripe**</span> bananas")) +
theme(text = element_text(family = "Cabin",
colour = banana_colours$light_text),
plot.title = ggtext::element_markdown(
size = 18,
family = "Poppins",
colour = banana_colours$dark_text,
face = "bold")
)
Apply the same principle to the axes and caption
basic_plot +
scale_colour_manual(values = banana_colours, limits = force) +
labs(title = paste0(
"Banana loaf tastes best when baked with ",
"<span style=\"color:", banana_colours$Chinstrap,
"\">ripe</span> or<br><span style=\"color:",
banana_colours$Gentoo, "\">over-ripe</span> bananas")) +
theme(text = element_text(family = "Cabin",
colour = banana_colours$light_text),
plot.title = ggtext::element_markdown(
size = 18,
family = "Poppins",
colour = banana_colours$dark_text,
face = "bold"),
axis.text = element_text(size = 6,
colour = banana_colours$light_text),
plot.caption = element_text(size = 6))
Getting custom fonts to work can be frustrating!
Install fonts locally +
{ragg}
+{systemfonts}
+{textshaping}
+ Set graphics device to āAGGā + š¤
See reference-scripts/02_setting-up-fonts.R
to get you started!
Choosing fonts can be tricky!
Find out more: pimpmytype.com/font-matrix/
systemfonts::system_fonts()
to see whatās installed alreadytheme()
elementsSee you in 15 minutes! šØ šļø ā
15:00
Combine all the above to create text boxes instead of a legend!
# Create a new tibble
penguin_summaries <- palmerpenguins::penguins %>%
group_by(species) %>%
summarise(bill_depth_mm = mean(bill_depth_mm, na.rm = TRUE),
bill_length_mm = mean(bill_length_mm, na.rm = TRUE)) %>%
mutate(commentary = case_when(species == "Adelie" ~
"The Adelie penguins tried varying the amount of banana in the mix.
Turns out, even a hint of green banana is detrimental to yumminess!",
species == "Gentoo" ~
"Over-ripe bananas and typically shorter baking times.",
TRUE ~ "Ripe bananas and slightly longer cooking times."))
Combine all the above to create text boxes instead of a legend!
basic_plot +
scale_colour_manual(values = banana_colours, limits = force) +
labs(title = paste0("Banana loaf tastes best when baked with <span style=\"color:", banana_colours$Chinstrap, "\">ripe</span> or<br><span style=\"color:", banana_colours$Gentoo, "\">over-ripe</span> bananas")) +
theme(text = element_text(family = "Cabin", colour = banana_colours$light_text),
plot.title = ggtext::element_markdown(size = 18, family = "Poppins", colour = banana_colours$dark_text, face = "bold"),
axis.text = element_text(size = 6, colour = banana_colours$light_text),
plot.caption = element_text(size = 6))
Combine all the above to create text boxes instead of a legend!
basic_plot +
scale_colour_manual(values = banana_colours, limits = force) +
labs(title = paste0("Banana loaf tastes best when baked with <span style=\"color:", banana_colours$Chinstrap, "\">ripe</span> or<br><span style=\"color:", banana_colours$Gentoo, "\">over-ripe</span> bananas")) +
ggtext::geom_textbox(data = penguin_summaries,
aes(label = paste0(
"**Team ", species, "**",
"<br><span style = \"color:",
banana_colours$light_text,
"\">", commentary, "</span>"))) +
theme(text = element_text(family = "Cabin", colour = banana_colours$light_text),
plot.title = ggtext::element_markdown(size = 18, family = "Poppins", colour = banana_colours$dark_text, face = "bold"),
axis.text = element_text(size = 6, colour = banana_colours$light_text),
plot.caption = element_text(size = 6))
Combine all the above to create text boxes instead of a legend!
basic_plot +
scale_colour_manual(values = banana_colours, limits = force) +
labs(title = paste0("Banana loaf tastes best when baked with <span style=\"color:", banana_colours$Chinstrap, "\">ripe</span> or<br><span style=\"color:", banana_colours$Gentoo, "\">over-ripe</span> bananas")) +
ggtext::geom_textbox(data = penguin_summaries,
aes(label = paste0(
"**Team ", species, "**",
"<br><span style = \"color:",
banana_colours$light_text,
"\">", commentary, "</span>")),
family = "Cabin",
size = 3.5,
width = unit(9, "line"),
alpha = 0.9,
box.colour = NA) +
theme(text = element_text(family = "Cabin", colour = banana_colours$light_text),
plot.title = ggtext::element_markdown(size = 18, family = "Poppins", colour = banana_colours$dark_text, face = "bold"),
axis.text = element_text(size = 6, colour = banana_colours$light_text),
plot.caption = element_text(size = 6))
Combine all the above to create text boxes instead of a legend!
basic_plot +
scale_colour_manual(values = banana_colours, limits = force) +
labs(title = paste0("Banana loaf tastes best when baked with <span style=\"color:", banana_colours$Chinstrap, "\">ripe</span> or<br><span style=\"color:", banana_colours$Gentoo, "\">over-ripe</span> bananas"),
subtitle = "The Palmer Penguins carried out an experiment using bananas of different ripeness.
Each penguin was left to choose their own cooking time.") +
ggtext::geom_textbox(data = penguin_summaries,
aes(label = paste0(
"**Team ", species, "**",
"<br><span style = \"color:",
banana_colours$light_text,
"\">", commentary, "</span>")),
family = "Cabin",
size = 3.5,
width = unit(9, "line"),
alpha = 0.9,
box.colour = NA) +
theme(text = element_text(family = "Cabin", colour = banana_colours$light_text),
plot.title = ggtext::element_markdown(size = 18, family = "Poppins", colour = banana_colours$dark_text, face = "bold"),
axis.text = element_text(size = 6, colour = banana_colours$light_text),
plot.caption = element_text(size = 6),
legend.position = "none")
To find the coordinates of the points you want to highlight, try plotly::ggplotly()
!
First, a bit of text manipulation!
penguin_highlights <- palmerpenguins::penguins_raw %>%
# Housekeeping
janitor::clean_names() %>%
rename(bill_depth_mm = culmen_depth_mm,
bill_length_mm = culmen_length_mm) %>%
# Find star baker, runner up and lowest score
filter(bill_length_mm %in% c(max(bill_length_mm, na.rm = TRUE),
sort(bill_length_mm, decreasing = TRUE)[2],
min(bill_length_mm, na.rm = TRUE)))
First, a bit of text manipulation!
penguin_highlights <- palmerpenguins::penguins_raw %>%
janitor::clean_names() %>%
rename(bill_depth_mm = culmen_depth_mm,
bill_length_mm = culmen_length_mm) %>%
filter(bill_length_mm %in% c(max(bill_length_mm, na.rm = TRUE),
sort(bill_length_mm, decreasing = TRUE)[2],
min(bill_length_mm, na.rm = TRUE))) %>%
# More housekeeping
mutate(species = gsub("(.) (.*)", "\\1", species))
First, a bit of text manipulation!
penguin_highlights <- palmerpenguins::penguins_raw %>%
janitor::clean_names() %>%
rename(bill_depth_mm = culmen_depth_mm,
bill_length_mm = culmen_length_mm) %>%
filter(bill_length_mm %in% c(max(bill_length_mm, na.rm = TRUE),
sort(bill_length_mm, decreasing = TRUE)[2],
min(bill_length_mm, na.rm = TRUE))) %>%
mutate(species = gsub("(.) (.*)", "\\1", species),
# Add commentary!
commentary = case_when(
bill_length_mm == max(bill_length_mm) ~
paste0("Our star baker is **", individual_id,
"**, a ", species, " from ", island,
". Congratulations, ", individual_id, "!"),
bill_length_mm == sort(bill_length_mm, decreasing = TRUE)[2] ~
paste0("Our runner up is a ", species,
" from ", island, ": **", individual_id,
"**, proving that ripe and over-ripe bananas are both good options!"),
TRUE ~ paste0("**", individual_id,
"**, did not have a good baking day. The combination of short cooking time and green bananas probably didn't help!")))
Next, letās work out where we want our labelsā¦
ā¦ and add box coordinates and text alignment to our data
penguin_highlights <- palmerpenguins::penguins_raw %>%
janitor::clean_names() %>%
rename(bill_depth_mm = culmen_depth_mm,
bill_length_mm = culmen_length_mm) %>%
filter(bill_length_mm %in% c(max(bill_length_mm, na.rm = TRUE),
sort(bill_length_mm, decreasing = TRUE)[2],
min(bill_length_mm, na.rm = TRUE))) %>%
# more housekeeping!
arrange(bill_length_mm) %>%
mutate(species = gsub("(.) (.*)", "\\1", species),
commentary = case_when(
bill_length_mm == max(bill_length_mm) ~
paste0("Our star baker is **", individual_id, "**, a ", species, " from ", island, ". Congratulations, ", individual_id, "!"),
bill_length_mm == sort(bill_length_mm, decreasing = TRUE)[2] ~
paste0("Our runner up is a ", species, " from ", island, ": **", individual_id, "**, proving that ripe and over-ripe bananas are both good options!"),
TRUE ~ paste0("**", individual_id, "**, did not have a good baking day. The combination of short cooking time and green bananas probably didn't help!")),
# Add label and arrow coordinates
label_x = c(15, 18.15, 16.45),
label_y = c(34, 57, 59),
left_to_right = case_when(label_x < bill_depth_mm ~ 1,
TRUE ~ 0),
arrow_x_end = case_when(label_x < bill_depth_mm ~ bill_depth_mm - 0.1,
TRUE ~ bill_depth_mm + 0.1),
arrow_y_end = case_when(label_y < bill_length_mm ~ bill_length_mm - 0.1,
TRUE ~ bill_length_mm + 0.1))
Find out more: cararthompson.com/posts/2021-09-02-alignment-cheat-sheet/
Letās add the annotationsā¦
basic_plot +
scale_colour_manual(values = banana_colours) +
labs(title = paste0("Banana loaf tastes best when baked with <span style=\"color:", banana_colours$Chinstrap, "\">ripe</span> or<br><span style=\"color:", banana_colours$Gentoo, "\">over-ripe</span> bananas"),
subtitle = "The Palmer Penguins carried out an experiment using bananas of different ripeness. \nEach penguin was left to choose their own cooking time.") +
ggtext::geom_textbox(data = penguin_summaries,
aes(label = paste0("**Team ", species, "**", "<br><span style = \"color:", banana_colours$light_text, "\">", commentary, "</span>")),
family = "Cabin", size = 3.5, width = unit(9, "line"), alpha = 0.9, box.colour = NA) +
theme(text = element_text(family = "Cabin", colour = banana_colours$light_text),
plot.title = ggtext::element_markdown(size = 18, family = "Poppins", colour = banana_colours$dark_text, face = "bold"),
axis.text = element_text(size = 6, colour = banana_colours$light_text),
plot.caption = element_text(size = 6),
legend.position = "none")
Letās add the annotationsā¦
basic_plot +
scale_colour_manual(values = banana_colours) +
labs(title = paste0("Banana loaf tastes best when baked with <span style=\"color:", banana_colours$Chinstrap, "\">ripe</span> or<br><span style=\"color:", banana_colours$Gentoo, "\">over-ripe</span> bananas"),
subtitle = "The Palmer Penguins carried out an experiment using bananas of different ripeness. \nEach penguin was left to choose their own cooking time.") +
ggtext::geom_textbox(data = penguin_summaries,
aes(label = paste0("**Team ", species, "**", "<br><span style = \"color:", banana_colours$light_text, "\">", commentary, "</span>")),
family = "Cabin", size = 3.5, width = unit(9, "line"), alpha = 0.9, box.colour = NA) +
ggtext::geom_textbox(data = penguin_highlights,
aes(label = commentary,
x = label_x,
y = label_y,
# alignment of the box with the box coordinate
hjust = left_to_right),
family = "Cabin",
size = 3,
fill = NA,
box.colour = NA) +
theme(text = element_text(family = "Cabin", colour = banana_colours$light_text),
plot.title = ggtext::element_markdown(size = 18, family = "Poppins", colour = banana_colours$dark_text, face = "bold"),
axis.text = element_text(size = 6, colour = banana_colours$light_text),
plot.caption = element_text(size = 6),
legend.position = "none")
ā¦ using arrows and alignments to emphasise the story
basic_plot +
scale_colour_manual(values = banana_colours) +
labs(title = paste0("Banana loaf tastes best when baked with <span style=\"color:", banana_colours$Chinstrap, "\">ripe</span> or<br><span style=\"color:", banana_colours$Gentoo, "\">over-ripe</span> bananas"),
subtitle = "The Palmer Penguins carried out an experiment using bananas of different ripeness. \nEach penguin was left to choose their own cooking time.") +
ggtext::geom_textbox(data = penguin_summaries,
aes(label = paste0("**Team ", species, "**", "<br><span style = \"color:", banana_colours$light_text, "\">", commentary, "</span>")),
family = "Cabin", size = 3.5, width = unit(9, "line"), alpha = 0.9, box.colour = NA) +
ggtext::geom_textbox(data = penguin_highlights,
aes(label = commentary, x = label_x, y = label_y, hjust = left_to_right),
family = "Cabin", size = 3, fill = NA, box.colour = NA) +
geom_curve(data = penguin_highlights,
aes(x = label_x, xend = arrow_x_end,
y = label_y, yend = arrow_y_end),
arrow = arrow(length = unit(0.1, "cm")),
curvature = 0.15,
alpha = 0.5) +
theme(text = element_text(family = "Cabin", colour = banana_colours$light_text),
plot.title = ggtext::element_markdown(size = 18, family = "Poppins", colour = banana_colours$dark_text, face = "bold"),
axis.text = element_text(size = 6, colour = banana_colours$light_text),
plot.caption = element_text(size = 6),
legend.position = "none")
ā¦ using arrows and alignments to emphasise the story
basic_plot +
scale_colour_manual(values = banana_colours) +
labs(title = paste0("Banana loaf tastes best when baked with <span style=\"color:", banana_colours$Chinstrap, "\">ripe</span> or<br><span style=\"color:", banana_colours$Gentoo, "\">over-ripe</span> bananas"),
subtitle = "The Palmer Penguins carried out an experiment using bananas of different ripeness. \nEach penguin was left to choose their own cooking time.") +
ggtext::geom_textbox(data = penguin_summaries,
aes(label = paste0("**Team ", species, "**", "<br><span style = \"color:", banana_colours$light_text, "\">", commentary, "</span>")),
family = "Cabin", size = 3.5, width = unit(9, "line"), alpha = 0.9, box.colour = NA) +
ggtext::geom_textbox(data = penguin_highlights,
aes(label = commentary, x = label_x, y = label_y, hjust = left_to_right,
halign = left_to_right),
family = "Cabin", size = 3, fill = NA, box.colour = NA) +
geom_curve(data = penguin_highlights,
aes(x = label_x, xend = arrow_x_end,
y = label_y, yend = arrow_y_end),
arrow = arrow(length = unit(0.1, "cm")),
curvature = 0.15,
alpha = 0.5) +
theme(text = element_text(family = "Cabin", colour = banana_colours$light_text),
plot.title = ggtext::element_markdown(size = 18, family = "Poppins", colour = banana_colours$dark_text, face = "bold"),
axis.text = element_text(size = 6, colour = banana_colours$light_text),
plot.caption = element_text(size = 6),
legend.position = "none")
Increase lineheight, reduce distractions
basic_plot +
scale_colour_manual(values = banana_colours) +
labs(title = paste0("Banana loaf tastes best when baked with <span style=\"color:", banana_colours$Chinstrap, "\">ripe</span> or<br><span style=\"color:", banana_colours$Gentoo, "\">over-ripe</span> bananas"),
subtitle = "The Palmer Penguins carried out an experiment using bananas of different ripeness. \nEach penguin was left to choose their own cooking time.") +
ggtext::geom_textbox(data = penguin_summaries,
aes(label = paste0("**Team ", species, "**", "<br><span style = \"color:", banana_colours$light_text, "\">", commentary, "</span>")),
family = "Cabin", size = 3.5, width = unit(9, "line"), alpha = 0.9, box.colour = NA) +
ggtext::geom_textbox(data = penguin_highlights,
aes(label = commentary, x = label_x, y = label_y, hjust = left_to_right, halign = left_to_right),
family = "Cabin", size = 3, fill = NA, box.colour = NA) +
geom_curve(data = penguin_highlights,
aes(x = label_x, xend = arrow_x_end, y = label_y, yend = arrow_y_end),
arrow = arrow(length = unit(0.1, "cm")), curvature = 0.15, alpha = 0.5) +
theme(text = element_text(family = "Cabin", colour = banana_colours$light_text),
plot.title = ggtext::element_markdown(size = 18, family = "Poppins", colour = banana_colours$dark_text, face = "bold"),
axis.text = element_text(size = 6, colour = banana_colours$light_text),
plot.caption = element_text(size = 6),
legend.position = "none")
Increase lineheight, reduce distractions
basic_plot +
scale_colour_manual(values = banana_colours) +
labs(title = paste0("Banana loaf tastes best when baked with <span style=\"color:", banana_colours$Chinstrap, "\">ripe</span> or<br><span style=\"color:", banana_colours$Gentoo, "\">over-ripe</span> bananas"),
subtitle = "The Palmer Penguins carried out an experiment using bananas of different ripeness. \nEach penguin was left to choose their own cooking time.") +
ggtext::geom_textbox(data = penguin_summaries,
aes(label = paste0("**Team ", species, "**", "<br><span style = \"color:", banana_colours$light_text, "\">", commentary, "</span>")),
family = "Cabin", size = 3.5, width = unit(9, "line"), alpha = 0.9, box.colour = NA) +
ggtext::geom_textbox(data = penguin_highlights,
aes(label = commentary, x = label_x, y = label_y, hjust = left_to_right, halign = left_to_right),
family = "Cabin", size = 3, fill = NA, box.colour = NA) +
geom_curve(data = penguin_highlights,
aes(x = label_x, xend = arrow_x_end, y = label_y, yend = arrow_y_end),
arrow = arrow(length = unit(0.1, "cm")), curvature = 0.15, alpha = 0.5) +
theme(text = element_text(family = "Cabin", colour = banana_colours$light_text,
lineheight = 1.2),
plot.title = ggtext::element_markdown(size = 18, family = "Poppins", colour = banana_colours$dark_text, face = "bold"),
axis.text = element_text(size = 6, colour = banana_colours$light_text),
plot.caption = element_text(size = 6),
legend.position = "none")
Increase lineheight, reduce distractions
basic_plot +
scale_colour_manual(values = banana_colours) +
labs(title = paste0("Banana loaf tastes best when baked with <span style=\"color:", banana_colours$Chinstrap, "\">ripe</span> or<br><span style=\"color:", banana_colours$Gentoo, "\">over-ripe</span> bananas"),
subtitle = "The Palmer Penguins carried out an experiment using bananas of different ripeness. \nEach penguin was left to choose their own cooking time.") +
ggtext::geom_textbox(data = penguin_summaries,
aes(label = paste0("**Team ", species, "**", "<br><span style = \"color:", banana_colours$light_text, "\">", commentary, "</span>")),
family = "Cabin", size = 3.5, width = unit(9, "line"), alpha = 0.9, box.colour = NA) +
ggtext::geom_textbox(data = penguin_highlights,
aes(label = commentary, x = label_x, y = label_y, hjust = left_to_right, halign = left_to_right),
family = "Cabin", size = 3, fill = NA, box.colour = NA) +
geom_curve(data = penguin_highlights,
aes(x = label_x, xend = arrow_x_end, y = label_y, yend = arrow_y_end),
arrow = arrow(length = unit(0.1, "cm")), curvature = 0.15, alpha = 0.5) +
theme(text = element_text(family = "Cabin", colour = banana_colours$light_text,
lineheight = 1.2),
plot.title = ggtext::element_markdown(size = 18, family = "Poppins", colour = banana_colours$dark_text, face = "bold"),
axis.text = element_text(size = 6, colour = banana_colours$light_text),
plot.caption = element_text(size = 6),
panel.grid = element_line(colour = "#F6F6F5"),
legend.position = "none")
Increase lineheight, reduce distractions, check everything fits!
basic_plot +
scale_colour_manual(values = banana_colours) +
labs(title = paste0("Banana loaf tastes best when baked with <span style=\"color:", banana_colours$Chinstrap, "\">ripe</span> or<br><span style=\"color:", banana_colours$Gentoo, "\">over-ripe</span> bananas"),
subtitle = "The Palmer Penguins carried out an experiment using bananas of different ripeness. \nEach penguin was left to choose their own cooking time.") +
ggtext::geom_textbox(data = penguin_summaries,
aes(label = paste0("**Team ", species, "**", "<br><span style = \"color:", banana_colours$light_text, "\">", commentary, "</span>")),
family = "Cabin", size = 3.5, width = unit(9, "line"), alpha = 0.9, box.colour = NA) +
ggtext::geom_textbox(data = penguin_highlights,
aes(label = commentary, x = label_x, y = label_y, hjust = left_to_right, halign = left_to_right),
family = "Cabin", size = 3, fill = NA, box.colour = NA) +
geom_curve(data = penguin_highlights,
aes(x = label_x, xend = arrow_x_end, y = label_y, yend = arrow_y_end),
arrow = arrow(length = unit(0.1, "cm")), curvature = 0.15, alpha = 0.5) +
scale_x_continuous(expand = expansion(mult = c(0.2, 0.02))) +
theme(text = element_text(family = "Cabin", colour = banana_colours$light_text,
lineheight = 1.2),
plot.title = ggtext::element_markdown(size = 18, family = "Poppins", colour = banana_colours$dark_text, face = "bold"),
axis.text = element_text(size = 6, colour = banana_colours$light_text),
plot.caption = element_text(size = 6),
panel.grid = element_line(colour = "#F6F6F5"),
legend.position = "none")
aes()
call if possibleSee you in 15 minutes! š āØ ā
15:00
Slides and recording: cararthompson.com/talks/nhsr2022-level-up