1

I have used ggarrange to combine multiple ggplots onto one figure. For my purposes, the figure legend is too small and I need to be able to change the size. I also need to change what my figure legend says. Currently, each color is labeled A, B, and C but I need it to say 1, 2, and 3. I have edited my ggplot code to do this individually but when I use ggarrange to combine, I no longer have my saved labels.

stefan
  • 90,330
  • 6
  • 25
  • 51
sarah99
  • 23
  • 1
  • 5
  • 1
    It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including the code you tried and a snippet of your data or some fake data to reproduce your issue and to figure out a solution. – stefan Apr 20 '22 at 21:38

1 Answers1

2

You can add elements from ggplot to control legend sizing and title theme() controls sizing, color, and more labs() changes the names of the legend title. In the example, based on calling color or fill from your plots.

data("ToothGrowth")
library(ggpubr)
df <- ToothGrowth
df$dose <- as.factor(df$dose)

myTheme <- theme(legend.text = element_text(size = 12), 
                                  legend.title = element_text(size = 14), 
                                  legend.key.size = unit(2, 'cm'))

# Create some plots
# ::::::::::::::::::::::::::::::::::::::::::::::::::
# Box plot
bxp <- ggboxplot(df, 
                 x = "dose", 
                 y = "len",
                 color = "dose", 
                 palette = "jco")+ 
                 myTheme+
                labs(color = '1')
# Dot plot
dp <- ggdotplot(df, x = "dose", y = "len",
                color = "dose", palette = "jco")+ 
  myTheme+
  labs(color = '2')
# Density plot
dens <- ggdensity(df, x = "len", fill = "dose", palette = "jco")+ 
  myTheme+
  labs(fill = '3')

# Arrange
# ::::::::::::::::::::::::::::::::::::::::::::::::::
ggarrange(bxp, dp, dens, ncol = 2, nrow = 2)

after

Susan Switzer
  • 1,531
  • 8
  • 34