Change font size for ggplot2 figures (axes titles, labels and numbers)

45 Views Asked by At

I've been struggling to increase the size of my axes labels and titles for ggplot2 function, and really need help on this to increase readability of my figures please.

I've tried several suggestions here, mainly using theme() parameters (see example dataframe below) and base_size argument.

example.bp <- ggplot(data = a, aes(x = b, y = c, fill = b)) +
  stat_boxplot(aes(b,c),
               geom='errorbar', linetype=1, width=0.5) +
  geom_boxplot(alpha = 0.3) +
  stat_summary(fun.y=mean, geom="point", size = 1) +
  theme(legend.position="none") +
  xlab("B") +
  ylab("C") +
  theme(axis.text = element_text(size = rel(1.5), colour = "black"),
        axis.text.x = element_text(colour = "black", size = 12, hjust = 0.5, vjust = 0.5, angle = 0),
        axis.text.y = element_text(colour = "black", size = 12, hjust = 0.5, vjust = 0.5),
        panel.background = element_blank())

example.bp

example.bp + annotate(geom = "text", x=1, y=140, label = "n = 8", color = "black") +
  annotate(geom = "text", x=2, y=140, label = "n = 14", color = "black") +
  annotate(geom = "text", x=3, y=140, label = "n = 7", color = "black") +
  annotate(geom = "text", x=4, y=140, label = "n = 15", color = "black")
example.bp + geom_hline(yintercept = 0)

When I try these changes, there aren't error messages, but no changes reflect on the figures.

What are your best suggestions for changing font size of all labels and axes for ggplot2, and integrating this into existing code for the figures?

0

There are 0 best solutions below