I am trying to italicize part of my legend elements. I have been able to get the subsets I want italicized using the answer in this OP, but this then creates problems with how the text shows up.
Here is the data (slightly modified):
Behaviour Repeatability Age stage
Activity 0.1 PE A
Activity 0.5 PE2 A
Activity 0.5 PW B
Activity 0.5 A C
Activity 0.4 A2 C
Activity 0.4 PW1 B
Aggression 0.2 PE A
Aggression 0.3 PE2 A
Aggression 0.3 PW B
Aggression 0.4 A C
Aggression 0.3 A2 C
Aggression 0.0 PW1 B
Here is the plot (without the italics):
When I try to italicize the legend text that are in brackets based on this solution, the plot gets messed up:
The code I use to get this plot is below (minus unneeded formatting):
ggplot(df, aes(x = stage, y = Repeatability, shape = Behaviour, colour=Age, linetype=Age)) +
geom_point() +
scale_colour_manual(values = c("#D55E00", "#0072B2", "black", "black", "#CC79A7", "black"), name = "Study", breaks=c("A","A2", "PE", "PE"=="PE2", "PW", "PE"=="PW1"),
labels=c(
(expression("Taylor et al. 2012", paste(italic("\n 366 adults")))),
(expression("Boon et al. 2008", paste(italic("\n (71 adult females)")))),
(expression("This study", paste(italic("\n (102 juveniles)")))),
"This study",
(expression("Kelley et al. 2015", paste(italic("\n (16 yearlings)")))),
"This study")) +
theme(legend.key.size = unit(2.5, 'lines'))