5

I'm trying to create a panel of plots using ggarrange. I'm using the "labels" argument to create a title for each one, but the positioning is coming out differently for each plot depending on how long the title is. It seems that the longer the title, the further to the right the label gets printed.

How can I make all labels left-justified? I've tried using hjust or label.x, but this doesn't change things.

This is my code and the plot:

ggarrange(plot1,plot2,plot3,
          common.legend=TRUE,
          labels = c("asdf", "asdfasdf", "asdfasdfasdfsadfasdf"),
          hjust=-0.8,
          ncol = 2, nrow = 2)

enter image description here

LvG
  • 417
  • 1
  • 4
  • 11

3 Answers3

3

I am not sure whether this is the short-cut to your question but trying this may help :

    plot1 <- plot1 + theme(legend.position="left")+
            labs(title="asdf")
    plot2<- plot2 + theme(legend.position="left")+
            labs(title="asdfasf")
    plot3 <- plot3 + theme(legend.position="left")+
            labs(title="asdfasdfasfdsas")
    ggarrange(plot1,plot2,plot3,
      common.legend=TRUE,
      hjust=-0.8,
      ncol = 2, nrow = 2)

You can check: https://www.royfrancis.com/customising-ggplot2/

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Cool, yes that's a good shortcut. I'd love to know what the real problem is! But thanks, that will have to do for now. – LvG May 12 '21 at 08:41
1

In my opinion, you may use geom_text() to set the label first for every plot, then use ggarrange() to put all subfigures together.

ZhongxiGe
  • 11
  • 2
0

hjust works for horizontal shift and vjust for vertical. In my case, I kept hjust=-7 to keep the labels in the middle, and it worked. You have to try it based on your data.

Rajiv
  • 21
  • 2