0

I have four plots that I would like to label with the builtin cowplot labeler (in ggplot in r). My labels have very different lengths. I notice that when I plot these labels the position of the labels depend on the label length with longer labels further to the write (including the beginning of the label) than for shorter labels.

Example

egPlot <- ggplot(data = iris, aes(x = Petal.Length, y = Petal.Width)) + geom_point()
PlotList <- list(egPlot, egPlot, egPlot, egPlot)
Labels = c("Short", "Medium name", "Very long name goes here", "A")
cowplot::plot_grid(plotlist = PlotList, ncol = 2, labels = Labels)

Cowplot with different length names

What is going on here, and is there anything I can do about it? Using label_x to specify the x position seems to move all of the labels, while maintaining the differences in position between the.

ohnoplus
  • 1,205
  • 1
  • 17
  • 29

1 Answers1

1

This issue is discussed here: https://github.com/wilkelab/cowplot/issues/32

@clauswilke posts

"Apparently this is caused by the fact that the label font is proportional width. The effect of hjust depends on the width of the label, and that width varies."

So set hjust to zero, and then determine the location of the labels with label_x.

cowplot::plot_grid(plotlist = PlotList, ncol = 2, labels = Labels, hjust = 0, label_x = 0.2)

Better plot positions

ohnoplus
  • 1,205
  • 1
  • 17
  • 29