Can't label multi-panel figure in r while using ggplot

后端 未结 2 1340
生来不讨喜
生来不讨喜 2021-02-04 14:56

Sorry for the possibly simple question. I\'m a programmer, though I rarely deal with graphics, and after tearing my hair out for hours with this problem, it\'s time to get some

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-04 15:32

    You could use ggtitle and theme:

    df = data.frame(gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30))
    p = ggplot(df) + geom_point(aes(x = gp, y = y)) + ggtitle('a') + theme(plot.title=element_text(hjust=0))
    p2 = ggplot(df) + geom_point(aes(x = y, y = gp)) + ggtitle('b') + theme(plot.title=element_text(hjust=0))
    grid.arrange(p, p2, ncol = 2)
    

    enter image description here

提交回复
热议问题