Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change font size of titles from facet_wrap

Tags:

r

ggplot2

Reproducible example

set.seed(1)
df <- data.frame(A=rep(c("good","bad"),each=8),
                 B=rep(c("yes","no"),4),
                 C=sample(1:20,16),
                 stringsAsFactors=F) %>%
      group_by(A,B)

Question

I'd like to change the font size of the titles from facet_wrap ('bad' 'good')

ggplot(df, aes(x=B, y=C)) +
  geom_violin() +
  geom_point() +
  facet_wrap(~A, nrow=1) +
  theme_classic() + 
  theme( axis.text = element_text( size = 14 ),
         axis.text.x = element_text( size = 20 ),
         axis.title = element_text( size = 16, face = "bold" ),
         legend.position="none" )

Any ideas? Thanks!

like image 826
CPak Avatar asked Aug 10 '17 15:08

CPak


People also ask

How do you change the size of a facet label?

We can change size of facet labels, using strip. text it should passed with value to produce labels of desired size.

How do I change the font size on a post title in Wordpress?

In the Customizer choose Fonts, then under Headings change the font, style, and size. You will see the changes instantly. Click 'Save & Publish' to save your changes.

How do I change the font size on my blog title?

Under 'General Settings' you'll find 'Fonts & Typography'. You should be able to set the font and size for titles there. The default font size for the site title is 32px . You can change that to a lower size, such as 24px .


Video Answer


1 Answers

Set strip.text in the theme:

ggplot(df, aes(x=B, y=C)) +
    geom_violin() +
    geom_point() +
    facet_wrap(~A, nrow=1) +
    theme_classic() + 
    theme( axis.text = element_text( size = 14 ),
           axis.text.x = element_text( size = 20 ),
           axis.title = element_text( size = 16, face = "bold" ),
           legend.position="none",
           # The new stuff
           strip.text = element_text(size = 20))
like image 123
Nathan Werth Avatar answered Sep 17 '22 08:09

Nathan Werth