ggExtra icon indicating copy to clipboard operation
ggExtra copied to clipboard

support title alignment with the plot introduced in `ggplot2 3.3.0`

Open IndrajeetPatil opened this issue 5 years ago • 1 comments

The latest (3.3.0) release of ggplot2 introduced a way to align the plot titles with the plot:

# setup
set.seed(123)
library(ggplot2)
library(ggExtra)

# basic plot
p <- 
  ggplot(mtcars, aes(wt, mpg)) + geom_point() +
  labs(title = "this title is aligned with the plot and not the axis") + 
  theme(plot.title.position = "plot")

# title aligned with the plot
plot(p)

But this alignment is removed by ggExtra:

# setup
set.seed(123)
library(ggplot2)
library(ggExtra)

# basic plot
p <- 
  ggplot(mtcars, aes(wt, mpg)) + geom_point() +
  labs(title = "this title is aligned with the plot and not the axis") + 
  theme(plot.title.position = "plot")

# alignment removed
ggMarginal(p)

IndrajeetPatil avatar Apr 15 '20 10:04 IndrajeetPatil

I'm not sure if this would be all that feasible to support. We pull the title/subtitle grob out of the built scatter plot (see getTitleGrobs()). If the built scatter plot doesn't include modifications to the title/subtitle that come from theme() (e.g., plot.title.position), there wouldn't be an easy way for us to include those modifications. I suppose we could check for modifications such as alignment by inspecting the theme of the built scatter plot and applying those changes to the title/subtitle grob in a piecemeal way (i.e., one by one), but that would be kinda a pain.

crew102 avatar Apr 17 '20 14:04 crew102