-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] labs
for created plots
#43
Comments
|
Thanks for the clarification. I updated the issue title and description accordingly. |
Thanks for opening this issue, and thanks for mentioning It'd be great to see ExampleHere's why I prefer set.seed(42)
dat <- data.frame(
x = rnorm(100),
y = rnorm(100),
z = rnorm(100),
group = sample(c("A", "B"), size = 100, replace = TRUE)
)
library(ggplot2)
p1 <- ggplot(dat, aes(x, y, color = z)) +
geom_point(size = 5) +
labs(title = "Hello")
p2 <- ggplot(dat, aes(x, y, color = group)) +
geom_point(size = 5) +
theme(legend.position = "bottom") Patchworklibrary(patchwork)
p1 + p2 + plot_annotation(
title = "patchwork",
caption = "This is the caption.",
theme = theme(
plot.title = element_text(size = 20),
plot.caption = element_text(size = 20)
)
) Notice the plot panels are perfectly aligned, and it is easy to change the theme of the title and caption with the gridExtralibrary(gridExtra)
grid.arrange(
p1, p2, ncol = 2,
top = "gridExtra",
bottom = "This is a caption."
) Notice that the plot panels are not aligned, and you have to use Session infodevtools::session_info()
#> Session info -------------------------------------------------------------
#> setting value
#> version R version 3.4.4 (2018-03-15)
#> system x86_64, darwin17.4.0
#> ui unknown
#> language (EN)
#> collate en_US.UTF-8
#> tz America/New_York
#> date 2018-03-16
#> Packages -----------------------------------------------------------------
#> package * version date source
#> backports 1.1.2 2017-12-13 CRAN (R 3.4.4)
#> base * 3.4.4 2018-03-16 local
#> colorspace 1.3-2 2016-12-14 CRAN (R 3.4.3)
#> compiler 3.4.4 2018-03-16 local
#> curl 3.1 2017-12-12 CRAN (R 3.4.3)
#> datasets * 3.4.4 2018-03-16 local
#> devtools 1.13.5 2018-02-18 CRAN (R 3.4.3)
#> digest 0.6.15 2018-01-28 CRAN (R 3.4.3)
#> evaluate 0.10.1 2017-06-24 CRAN (R 3.4.4)
#> ggplot2 * 2.2.1.9000 2018-03-15 Github (thomasp85/ggplot2@f1ba983)
#> graphics * 3.4.4 2018-03-16 local
#> grDevices * 3.4.4 2018-03-16 local
#> grid 3.4.4 2018-03-16 local
#> gridExtra * 2.3 2017-09-09 CRAN (R 3.4.4)
#> gtable 0.2.0 2016-02-26 CRAN (R 3.4.3)
#> htmltools 0.3.6 2017-04-28 CRAN (R 3.4.3)
#> httr 1.3.1 2017-08-20 CRAN (R 3.4.3)
#> knitr 1.20 2018-02-20 CRAN (R 3.4.4)
#> labeling 0.3 2014-08-23 CRAN (R 3.4.3)
#> lazyeval 0.2.1 2017-10-29 CRAN (R 3.4.3)
#> magrittr 1.5 2014-11-22 CRAN (R 3.4.3)
#> memoise 1.1.0 2017-04-21 CRAN (R 3.4.3)
#> methods * 3.4.4 2018-03-16 local
#> mime 0.5 2016-07-07 CRAN (R 3.4.3)
#> munsell 0.4.3 2016-02-13 CRAN (R 3.4.3)
#> patchwork * 0.0.1 2018-03-15 Github (thomasp85/patchwork@49e6ba4)
#> pillar 1.2.1 2018-02-27 CRAN (R 3.4.3)
#> plyr 1.8.4 2016-06-08 CRAN (R 3.4.3)
#> R6 2.2.2 2017-06-17 CRAN (R 3.4.3)
#> Rcpp 0.12.16 2018-03-13 CRAN (R 3.4.3)
#> rlang 0.2.0.9000 2018-03-15 Github (tidyverse/rlang@1b81816)
#> rmarkdown 1.9 2018-03-01 CRAN (R 3.4.4)
#> rprojroot 1.3-2 2018-01-03 CRAN (R 3.4.4)
#> scales 0.5.0.9000 2018-03-15 Github (hadley/scales@d767915)
#> stats * 3.4.4 2018-03-16 local
#> stringi 1.1.7 2018-03-12 CRAN (R 3.4.3)
#> stringr 1.3.0 2018-02-19 CRAN (R 3.4.3)
#> tibble 1.4.2 2018-01-22 CRAN (R 3.4.3)
#> tools 3.4.4 2018-03-16 local
#> utils * 3.4.4 2018-03-16 local
#> withr 2.1.2 2018-03-15 Github (jimhester/withr@79d7b0d)
#> xml2 1.2.0 2018-01-24 CRAN (R 3.4.4)
#> yaml 2.1.18 2018-03-08 CRAN (R 3.4.3) |
Came here to suggest this feature for axis titles, so count me in as +1 |
+1 for adding this to the README. The plot_annotation() function is really handy so should be made clearer. Thanks for creating such a great package! |
Huge fan of Also agree that updating the README would be great. Thanks @thomasp85 for the really cool work! |
Documentation for |
I see that this issue has been closed. Does this mean that the feature (global labs) has been added or that it is no longer considered? |
Thanks @thomasp85 for this wonderful package. I would love to see x and y labels added to the Will this be forthcoming or have you closed this feature request because it is not feasible? Thanks again |
Just wanted to add another request for global x- and y-axis titles with
Another option would be to use the caption as a kludge to get a global x-axis title, but this precludes using the caption feature for an actual caption and is hackish:
Would it be possible to add an option to create a global x-axis title (and/or global y-axis title) using As another potential option, what about creating a
Maybe that's more trouble than it's worth, since such a feature would have to deal with cases where a user chooses "collect" even when each plot has a different x-axis title, or in cases where the plot layout has more than one column. Even then, in the first case you could return a warning. In the second, assuming all plots in a given column have the same x-axis title, "collect" could operate by column. |
I would find a common axis useful as well! |
Hello, I'd just like to add my support for global axes labels! Right now I individually hide axes labels for certain panels so that it appears as if there is global axes labels, but this is a cumbersome, manual process. For example, if I have p1 + p2 + p3, I hide all y labels except for p1, and hide all x labels except for p2. It would be much cleaner to have global axes labels. |
Agreed, global axes would be great. I really like the simplicity of patchwork. It's a bummer to have to revert to using another package to draw multiple plots together... |
I would also love if a global axis option was added :c |
+1! |
Yes please to a global axis option |
Based on this stackoverflow post, I've found you can add the same axis label to every subplot with the following:
@thomasp85 it's not super clear to me why the ampersand works here instead of the usual plus sign, maybe you could elaborate? I agree with the posters above that it would still be helpful to update |
I hacked a function to create global x label and y label, in an ugly way. I post here for anyone's interest. function
How to use:
|
This is excellent! Thank you! |
Thanks for this, really useful code. Couple of issues that are easy to overcome with it. First is that if using plot_layout() from patchwork for other purposes must be done after e.g.
Second more a comment for other to be aware. If plots have been passed through coord_flip then this function treats original Y axis as X-axis so to change the original Y-axis need to use Xlab argument |
+1 for a complete implementation of this functionality The hack fom @mingsu, while super useful (thank you!) does not align with the plot area only, but the full plot objects (including axis labels). I would expect the "count" to be aligned vertically at the gap between the two plots:
|
I agree this would be a very useful feature. It's unclear to me why the issue was closed. |
another workaround is offered here: https://stackoverflow.com/a/66778622/7941188 |
One option apparently is Even when we define different widths with plot_playout like the code below:
|
Despite the different options to get a centered x-axis it would still be nice to have a separate function for this. The mentioned solutions don't work well with the auto-tag feature. |
I have to agree - having global axis labels would be extremely useful, and makes sense in the |
Is Global axis ready? |
+1 |
@thomasp85 would you consider a PR that implemented this? |
I agree, this would be a very helpful feature. |
This has been implemented in #337 |
Would it be possible to add a global
labs
function that will affect the created plot?Title is straightforward, sometimes I have 3-4 figures and I want all of them to share one major title.
For X- and Y-axis labels, I often patchwork 4, 6, or 9 figures which have the same X- and Y-axis labels, I want to show one "big" label for each axis rather than many small labels.
Edit: As @thomasp85 points out below,
plot_annotation
takes care of this for the title, subtitle, and caption.The text was updated successfully, but these errors were encountered: