I'm trying to add the name of a species in italics to my patchwork
title, but I can't figure out how to do it, I keep getting an error message telling me that italic()
only supports flexible objects.
Any ideas ?
species <- c("Castanea sativa")
plot_title <- substitute(paste("Ex title", italic(x), sep=" "), list(x=species))
library(patchwork)
patchwork <- p1 | (p2/p3/p4) +
plot_annotation(
title = plot_title,
theme = theme(plot.title = element_text(size = 20, face="bold", hjust = 0.5)))
p <- wrap_elements(patchwork)
p
Error in italic("Castanea sativa") :
Function `italic()` supports only flextable objects.
OK, I installed patchwork
to test this:
library(ggplot2)
library(patchwork)
word <- 'italics'
df <- data.frame(x = 1:10, y = 10:1)
p1 <- ggplot(df, aes(x,y)) + geom_point()
p2 <- ggplot(df, aes(x,y)) + geom_point()
p1 + p2 + plot_annotation(title = substitute("Ex title" ~ italic(x), list(x=word)))