Skip to content

Instantly share code, notes, and snippets.

@ryanbthomas
Created October 16, 2020 17:33
Show Gist options
  • Save ryanbthomas/775290b7d446a731fccb38a73388d33d to your computer and use it in GitHub Desktop.
Save ryanbthomas/775290b7d446a731fccb38a73388d33d to your computer and use it in GitHub Desktop.
Example of adding color to plot title instead of legend
library(GLMsData) #where the flowers dataset comes from
library(dplyr)
library(ggplot)
library(ggtext)
flowers %>%
group_by(Timing, Light) %>%
summarise(expFlowers = mean(Flowers)) %>%
ggplot() +
aes(x = Light, y = expFlowers, group = Timing, color = Timing) +
geom_line(size = 1.5) +
geom_point(size = 3) +
scale_color_manual(values = c("#d83177", "#6c31d8")) +
labs(title = "Mean number of flowers per meadowfoam plant at <span style='color: #6c31d8'>**PFI**</span> vs <span style='color: #d83177'>**24 days before PFI**</span>") +
xlab("Light Exposure") +
theme_minimal() +
theme(
plot.title.position = "plot",
plot.title = element_textbox_simple(
size = 16,
lineheight = 1,
padding = margin(5.5, 5.5, 5.5, 5.5),
margin = margin(0, 0, 5.5, 0)
),
axis.title.y = element_blank(),
legend.position = "none"
)
@ryanbthomas
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment