从facet_wrap更改标题的字体大小

时间:2017-08-10 15:44:18

标签: r ggplot2

可重复的例子

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)

问题

我想改变标题的字体大小facet_wrap('坏''好')

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" )

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:7)

strip.text

中设置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))