Change font size in ggplot2 (facet_wrap)

Hi everyone,

When I run the following code

library(palmerpenguins)
data('penguins')
ggplot(drop_na(penguins),aes(species, body_mass_g, fill = species)) + 
  geom_violin(
      show.legend = FALSE,
      outlier.shape = 21, # A number 0:25 , NA will hide the outliers
      outlier.size = 3,
      outlier.fill = 'red'
  ) + 
  facet_wrap(sex ~ ., scales = 'free_x', ncol = 1) + 
  scale_y_continuous(limits = c(2000,7000), n.breaks = 10) + 
  theme(
    axis.text.x = element_text(angle = 45, size = 20, vjust = 0.65),
    axis.text.y = element_text(angle = 45, size = 15), 
    axis.title = element_text(size = 25, color = 'steelblue')
  ) + 
  coord_cartesian(ylim = c(2500, 6500)) 

Notice how the 'male' & 'female' appear too small my question is how can I increase their size and color.

Thanks :slightly_smiling_face:

I'd do it along the following lines

library(palmerpenguins)
library(ggplot2)
library(tidyr)
data('penguins')
ggplot(drop_na(penguins),aes(species, body_mass_g, fill = species)) + 
  geom_violin(
    # show.legend = FALSE,
    # outlier.shape = 21, # A number 0:25 , NA will hide the outliers
    # outlier.size = 3,
    # outlier.fill = 'red'
  ) + 
  facet_wrap(sex ~ ., scales = 'free_x', ncol = 1) + 
  scale_y_continuous(limits = c(2000,7000), n.breaks = 10) + 
  theme(
    axis.text.x = element_text(size = 20, vjust = 0.65),
    axis.text.y = element_text(size = 10), 
    axis.title = element_text(size = 25, color = 'steelblue'),
    strip.text = element_text(size=25, color = 'steelblue'),
    strip.background = element_blank()) +
  coord_cartesian(ylim = c(2500, 6500)) 

1 Like

Thanks again Richard :slightly_smiling_face: :slightly_smiling_face:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.