library(grid)
library(gridtext) # devtools::install_github("clauswilke/gridtext")
library(gridExtra)
library(ggplot2)
ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
geom_point() +
labs(title = "Replace-able") -> gg
gb <- ggplot_build(gg)
gt <- ggplot_gtable(gb)
title <- "<span style='font-size:20'>Iris </span><span style='font-size:12'>[some text]</span>"
tg <- rich_text_grob(title, x = unit(0, "lines"), y = unit(2, "lines"))
gt$grobs[[16]] <- tg
grid.newpage()
grid.draw(gt)
然后,有:
ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
geom_point() -> gg
title <- "<span style='font-size:20'>Iris </span><span style='font-size:12'>[some text]</span>"
tg <- rich_text_grob(title, x = unit(2, "lines"), y = unit(2, "lines"))
grid.newpage()
grid.draw(
arrangeGrob(tg, gg, heights=c(0.1, 0.8))
)