Created
August 3, 2020 17:44
-
-
Save ryanbthomas/3905467074c8882a02406db80c5674cd to your computer and use it in GitHub Desktop.
Example of using ggtext to add color to specific words in plot title instead of using a legend.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggtext) | |
# flowers data from the GLMsData package. | |
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" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment