I am creating ggplots with label strings from a list, sometimes adjusted with an if-else function depending on content. If the title contains superscript or subscript I am parsing the title to get the required format. However, when adding a ggtitle with a parsed string the bold part of the theme is not implemented.
In the simplest form this is what i am working with:
library(ggplot2) #charts
library(gridExtra)
df <- data.frame(Letter_x=c(LETTERS[1:3]), Value_y=c(1:3))
my_title1 = parse(text="NO[3]")
my_title2 = "NO3"
plot_theme = theme(
plot.title = element_text(size = 14, face = "bold", margin=margin(0, 0, 3, 0), hjust=.5)
)
p1 <- ggplot(df, aes(Letter_x, Value_y)) +
geom_point() +
ggtitle(my_title1)+
plot_theme
p2 <- ggplot(df, aes(Letter_x, Value_y)) +
geom_point() +
ggtitle(my_title2)+
plot_theme
grid.arrange(p1, p2, ncol=2, nrow = 1)
I would like both resulting charts to have bold titles:
Charts with different title font-weight