Skip to content

Enhance patchwork #379

@Yunuuuu

Description

@Yunuuuu

I have created some features for patchwork, which will modifying the core codes of patchwork. I hope these features can be merged into patchwork. These functions are now deposited in https://github.com/Yunuuuu/ggalign (See scripts begin with alignpatch-)

  1. free_align: if we want to compose plots without alignment of some panel axes (panel won't be aligned). we can wrap the plot with free_align. Note: this is different from free function (the current free function is much like the wrap_elements() function), it only free the selected axes.
p1 <- ggplot(mtcars) +
    geom_point(aes(mpg, disp)) +
    ggtitle("Plot 1")

p3 <- ggplot(mtcars) +
    geom_point(aes(hp, wt, colour = mpg)) +
    ggtitle("Plot 3")

p5 <- ggplot(mpg, aes(class)) +
    geom_bar() +
    ylim(0, 65) +
    coord_flip()
plot_grid(free_align(p3, "l"), p5, ncol = 1L)

image

  1. free_border: If we want to compose plots without alignment of the panel borders (but still align the panels themselves), we can wrap the plot with free_border. This does the same work with cowplot::plot_grid by setting axis argument, we only align the panel, but border like axis titles won't be aligned. Note title, subtitle, and caption won't be aligned too. If you want to free axes and axes title, try to use free_lab
plot_grid(free_border(p3, "l"), p5, ncol = 1L)

image

  1. free_lab: Similar with free_border, but it will only operate the axis and axis title (labs). If we want to compose plots without alignment of the axis title, we can wrap the plot with free_lab. This should fix Gap between axis label and text if adjacent plot has vertical axis text #285, [Feature Request] Align panels without aligning axis titles #348 and axis panel size should be determind by its own axis label size #110 (comment).
plot_grid(free_lab(p3, "l"), p5, ncol = 1L)

image

  1. free_size: Removing the ggplot element sizes when aligning, we ususally want to combine this with free_border to suspend the empty sized ggplot elements. Note the the second plot (on right-top), the left side of the panel won't count space when aligned. This help make more compact layout
plot_grid(
  patchwork::plot_spacer(), 
  free_size(free_border(p5, "l"), "l"),
  p1, p3, nrow = 2L
)

image

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