patchwork
patchwork copied to clipboard
How to cancel/NULLify a title?
Hi
It seems that if a main title has been added with plot_annotation(title)
, it is not possible to remove it/NULLify it ex-post? This is possible with ggplot2 with ggtitle(NULL)
, and very useful (say keep for analysis plots with title yet remove titles for publication, as title will be included in the text software?), is it possible to do with patchwork
too?
Thanks!
library(ggplot2)
library(patchwork)
packageVersion("patchwork")
#> [1] '1.0.1.9000'
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) + ggtitle("Some Tiltle")
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
## Standrad ggplot allows to NULLify a title
p1 + ggtitle(NULL)
# But not possible with patchwork?
p3 <- p1 + p2 + plot_annotation('This is a title I want to remove ex-post', caption = 'made with patchwork')
p3 + plot_annotation(title=NULL)
Created on 2020-07-01 by the reprex package (v0.3.0)
Hi, I just found an alternative way to remove the title added in plot_annotation
(PS: I'm not using the same patchwork version, but I think it should work for version 1.0.1)
library(ggplot2)
library(patchwork)
packageVersion("patchwork")
#> [1] '1.1.1'
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) + ggtitle("Some Tiltle")
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
p3 <- p1 + p2 + plot_annotation('This is a title I want to remove ex-post', caption = 'made with patchwork')
p3$patches$annotation$title <- NULL
p3
Created on 2022-09-21 with reprex v2.0.2
thanks a lot @Ning-L !!
Hopefully, the maintainers might be able to make this as a feature of the package though!? :-)