Created
October 16, 2020 17:33
-
-
Save ryanbthomas/775290b7d446a731fccb38a73388d33d to your computer and use it in GitHub Desktop.
Example of adding color to plot title instead of 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(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" | |
) |
Author
ryanbthomas
commented
Oct 16, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment