Daniel Valencia C.
Daniel Valencia C.

Reputation: 2279

How to change the size and color of tags globally using ggplot2 and ggpubr?

I have 3 plots in an array using ggarrange from the ggpubr package. The size and font of the tags can be modified within the ggarrange() function, as I present it in MWE. Is there any way to make this modification globally, maybe inside theme_set() or theme(), so that it applies to all plots?

library(ggplot2)
library(ggpubr)

p <- ggscatter(iris, x = "Sepal.Length", y = "Sepal.Width",
               color = "Species", palette = "jco",
               ggtheme = theme_minimal())

ggarrange(p, p, p,
          ncol = 3,
          common.legend = TRUE,
          labels = c("a", "b", "c"),
          font.label = list(size = 15,
                            color = "red"))

enter image description here

Upvotes: 1

Views: 430

Answers (1)

stefan
stefan

Reputation: 124863

One option would be to make a small wrapper which under the hood calls ggarrange with your desired defaults and which could easily be applied to all your plots:

library(ggplot2)
library(ggpubr)

p <- ggscatter(iris, x = "Sepal.Length", y = "Sepal.Width",
               color = "Species", palette = "jco",
               ggtheme = theme_minimal())

ggarrange1 <- function(..., ncol = NULL, labels = "auto") {
  ggarrange(..., ncol = ncol, labels = labels, common.legend = TRUE, font.label = list(size = 15,color = "red"))
}

ggarrange1(p, p, p, ncol = 3)

Upvotes: 1

Related Questions