Skip to content

Manual position of collected guides #177

Description

@costavale

I would like to be able to manually decide the position of the legend(s).
In the case of collected guides, and with a defined design it will be very useful to be able to manually put the legend in a blank space btw figures.

Activity

  1. thomasp85 commented on May 12, 2020

    @thomasp85
    Owner

    Have a look at guide_area() 🙂

  2. costavale commented on May 12, 2020

    @costavale
    Author

    Thank you! (....and what about the justification of the collected guides? thk)

  3. thomasp85 commented on May 12, 2020

    @thomasp85
    Owner

    These can be set in the patchwork theme

  4. MokeEire commented on Nov 23, 2020

    @MokeEire

    Is there a way to position the collected guides inside the plot area of one panel? The following naive attempt did not work:

    p1 + p2 + 
        inset_element(guide_area(), left = 0.6, bottom = 0.6, right = 1, top = 1) +
        plot_layout(guides = "collect")
    

    The way I was able to get the result I wanted was to set legend.position = "none" on the left panel and legend.position = c(.15, .9) on the right panel.

    image

  5. jarbet commented on Mar 26, 2026

    @jarbet

    I case anyone else is wondering, guide_area can also be used with wrap_plots:

    suppressPackageStartupMessages({
        library(ggplot2)
        library(patchwork)
    })
    p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp, colour = factor(gear)))
    p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
    p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)
    
    # Using guide_area() you can also designate an empty area for this
    p1 + p2 + p3 + guide_area() + plot_layout(guides = 'collect')
    
    ### using wrap_plots:
    plot_list <- list(
        p1,
        p2,
        p3,
        guide_area()
    )
    patchwork::wrap_plots(
        plot_list,
        ncol = 2,
        guides = 'collect'
    )
    
    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions