patchwork/ 0000755 0001762 0000144 00000000000 14547004502 012255 5 ustar ligges users patchwork/NAMESPACE 0000644 0001762 0000144 00000010024 14545741755 013511 0 ustar ligges users # Generated by roxygen2: do not edit by hand
S3method("&",gg)
S3method("*",gg)
S3method("-",ggplot)
S3method("/",ggplot)
S3method("[[",patchwork)
S3method("[[<-",patchwork)
S3method("|",ggplot)
S3method(add_patches,ggplot)
S3method(add_patches,patchwork)
S3method(as_patch,formula)
S3method(as_patch,gList)
S3method(as_patch,ggplot)
S3method(as_patch,grob)
S3method(as_patch,nativeRaster)
S3method(as_patch,patchwork)
S3method(as_patch,raster)
S3method(as_patchwork,default)
S3method(as_patchwork,ggplot)
S3method(as_patchwork,patchwork)
S3method(c,patch_area)
S3method(get_dim,ggplot)
S3method(get_dim,patchwork)
S3method(ggplot_add,formula)
S3method(ggplot_add,ggplot)
S3method(ggplot_add,grob)
S3method(ggplot_add,nativeRaster)
S3method(ggplot_add,plot_annotation)
S3method(ggplot_add,plot_layout)
S3method(ggplot_add,raster)
S3method(ggplot_build,fixed_dim_ggplot)
S3method(ggplot_gtable,fixed_dim_build)
S3method(has_tag,ggplot)
S3method(has_tag,guide_area)
S3method(has_tag,inset_patch)
S3method(has_tag,plot_filler)
S3method(has_tag,spacer)
S3method(has_tag,wrapped_patch)
S3method(length,patch_area)
S3method(length,patchwork)
S3method(names,patchwork)
S3method(patchGrob,guide_area)
S3method(patchGrob,patch)
S3method(patchGrob,table_patch)
S3method(patchGrob,wrapped_patch)
S3method(plot,inset_patch)
S3method(plot,patch)
S3method(plot,patch_area)
S3method(plot,patchwork)
S3method(plot_table,free_plot)
S3method(plot_table,ggplot)
S3method(plot_table,inset_patch)
S3method(plot_table,patch)
S3method(plot_table,patchwork)
S3method(print,inset_patch)
S3method(print,patch)
S3method(print,patch_area)
S3method(print,patchwork)
S3method(print,plot_dimension)
S3method(set_dim,ggplot)
S3method(set_dim,patchwork)
S3method(simplify_gt,gtable)
S3method(simplify_gt,gtable_patchwork)
S3method(simplify_gt,inset_table)
S3method(simplify_gt,patchgrob)
S3method(str,patchwork)
export(align_patches)
export(align_plots)
export(area)
export(free)
export(get_dim)
export(get_max_dim)
export(guide_area)
export(inset_element)
export(patchGrob)
export(patchworkGrob)
export(plot_annotation)
export(plot_layout)
export(plot_spacer)
export(set_dim)
export(wrap_elements)
export(wrap_ggplot_grob)
export(wrap_plots)
import(cli)
import(rlang)
importFrom(ggplot2,aes)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_grob)
importFrom(ggplot2,element_line)
importFrom(ggplot2,element_text)
importFrom(ggplot2,find_panel)
importFrom(ggplot2,geom_blank)
importFrom(ggplot2,geom_rect)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggplotGrob)
importFrom(ggplot2,ggplot_add)
importFrom(ggplot2,ggplot_build)
importFrom(ggplot2,ggplot_gtable)
importFrom(ggplot2,is.ggplot)
importFrom(ggplot2,is.theme)
importFrom(ggplot2,labs)
importFrom(ggplot2,margin)
importFrom(ggplot2,max_height)
importFrom(ggplot2,max_width)
importFrom(ggplot2,panel_cols)
importFrom(ggplot2,panel_rows)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,scale_y_reverse)
importFrom(ggplot2,set_last_plot)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_get)
importFrom(ggplot2,theme_void)
importFrom(ggplot2,wrap_dims)
importFrom(ggplot2,zeroGrob)
importFrom(grDevices,is.raster)
importFrom(grid,absolute.size)
importFrom(grid,convertHeight)
importFrom(grid,convertWidth)
importFrom(grid,editGrob)
importFrom(grid,gTree)
importFrom(grid,grid.draw)
importFrom(grid,grid.newpage)
importFrom(grid,grobHeight)
importFrom(grid,heightDetails)
importFrom(grid,is.grob)
importFrom(grid,is.unit)
importFrom(grid,pushViewport)
importFrom(grid,rasterGrob)
importFrom(grid,seekViewport)
importFrom(grid,unit)
importFrom(grid,unit.c)
importFrom(grid,unit.pmax)
importFrom(grid,upViewport)
importFrom(grid,valid.just)
importFrom(grid,viewport)
importFrom(grid,widthDetails)
importFrom(gtable,gtable)
importFrom(gtable,gtable_add_cols)
importFrom(gtable,gtable_add_grob)
importFrom(gtable,gtable_add_rows)
importFrom(gtable,gtable_height)
importFrom(gtable,gtable_width)
importFrom(gtable,is.gtable)
importFrom(stats,ave)
importFrom(stats,na.omit)
importFrom(utils,as.roman)
importFrom(utils,modifyList)
importFrom(utils,str)
importFrom(utils,tail)
patchwork/LICENSE 0000644 0001762 0000144 00000000061 13207337010 013252 0 ustar ligges users YEAR: 2017
COPYRIGHT HOLDER: Thomas Lin Pedersen
patchwork/README.md 0000644 0001762 0000144 00000005510 14545740747 013555 0 ustar ligges users
# patchwork
[](https://github.com/thomasp85/patchwork/actions/workflows/R-CMD-check.yaml)
[](https://CRAN.R-project.org/package=patchwork)
[](https://CRAN.R-project.org/package=patchwork)
[](https://app.codecov.io/gh/thomasp85/patchwork?branch=main)
The goal of `patchwork` is to make it ridiculously simple to combine
separate ggplots into the same graphic. As such it tries to solve the
same problem as `gridExtra::grid.arrange()` and `cowplot::plot_grid` but
using an API that incites exploration and iteration, and scales to
arbitrarily complex layouts.
## Installation
You can install patchwork from CRAN using
`install.packages('patchwork')`. Alternatively you can grab the
development version from github using devtools:
``` r
# install.packages("devtools")
devtools::install_github("thomasp85/patchwork")
```
## Basic example
The usage of `patchwork` is simple: just add plots together!
``` r
library(ggplot2)
library(patchwork)
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
p1 + p2
```

patchwork provides rich support for arbitrarily complex layouts with
full alignment. As an example, check out this very readable code for
nesting three plots on top of a third:
``` r
p3 <- ggplot(mtcars) + geom_smooth(aes(disp, qsec))
p4 <- ggplot(mtcars) + geom_bar(aes(carb))
(p1 | p2 | p3) /
p4
```

## Learn more
patchwork can do so much more. Check out the guides for learning
everything there is to know about all the different features:
- [Getting
Started](https://patchwork.data-imaginist.com/articles/patchwork.html)
- [Assembling
Plots](https://patchwork.data-imaginist.com/articles/guides/assembly.html)
- [Defining
Layouts](https://patchwork.data-imaginist.com/articles/guides/layout.html)
- [Adding
Annotation](https://patchwork.data-imaginist.com/articles/guides/annotation.html)
- [Aligning across
pages](https://patchwork.data-imaginist.com/articles/guides/multipage.html)
## Code of Conduct
Please note that the patchwork project is released with a [Contributor
Code of
Conduct](https://patchwork.data-imaginist.com/CODE_OF_CONDUCT.html). By
contributing to this project, you agree to abide by its terms.
patchwork/man/ 0000755 0001762 0000144 00000000000 14545742247 013045 5 ustar ligges users patchwork/man/area.Rd 0000644 0001762 0000144 00000003347 14277433671 014253 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot_layout.R
\name{area}
\alias{area}
\title{Specify a plotting area in a layout}
\usage{
area(t, l, b = t, r = l)
}
\arguments{
\item{t, b}{The top and bottom bounds of the area in the grid}
\item{l, r}{The left and right bounds of the area int the grid}
}
\value{
A \code{patch_area} object
}
\description{
This is a small helper used to specify a single area in a rectangular grid
that should contain a plot. Objects constructed with \code{area()} can be
concatenated together with \code{c()} in order to specify multiple areas.
}
\details{
The grid that the areas are specified in reference to enumerate rows from top
to bottom, and coloumns from left to right. This means that \code{t} and \code{l}
should always be less or equal to \code{b} and \code{r} respectively. Instead of
specifying area placement with a combination of \code{area()} calls, it is
possible to instead pass in a single string
\if{html}{\out{
}}\preformatted{areas <- c(area(1, 1, 2, 1),
area(2, 3, 3, 3))
}\if{html}{\out{
}}
is equivalent to
\if{html}{\out{}}\preformatted{areas < -"A##
A#B
##B"
}\if{html}{\out{
}}
For an example of this, see the \code{\link[=plot_layout]{plot_layout()}} examples.
}
\examples{
library(ggplot2)
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)
layout <- c(
area(1, 1),
area(1, 3, 3),
area(3, 1, 3, 2)
)
# Show the layout to make sure it looks as it should
plot(layout)
# Apply it to a patchwork
p1 + p2 + p3 + plot_layout(design = layout)
}
patchwork/man/patchwork-package.Rd 0000644 0001762 0000144 00000004762 14277433671 016740 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/patchwork-package.r
\docType{package}
\name{patchwork-package}
\alias{patchwork}
\alias{patchwork-package}
\title{patchwork: The Composer of Plots}
\description{
\if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}}
The 'ggplot2' package provides a strong API for sequentially building up a plot, but does not concern itself with composition of multiple plots. 'patchwork' is a package that expands the API to allow for arbitrarily complex composition of plots by, among others, providing mathematical operators for combining multiple plots. Other packages that try to address this need (but with a different approach) are 'gridExtra' and 'cowplot'.
}
\section{Overview}{
The use and premise of \code{patchwork} is simple: Just add \code{ggplot2} plots
together to compose multiplot layouts. Because of this simplicity there is
not much more to say. Still, a few functions allow you to modify the
behaviour, e.g.:
\itemize{
\item \code{\link[=plot_layout]{plot_layout()}} allows you to define the grid that plots are put into
\item \code{\link[=plot_annotation]{plot_annotation()}} allows you to add titles, tags etc.
}
}
\section{Learn more}{
The guides below will teach you all about what you can do with patchwork.
\itemize{
\item \href{https://patchwork.data-imaginist.com/articles/patchwork.html}{Getting Started}
\item \href{https://patchwork.data-imaginist.com/articles/guides/assembly.html}{Assembling Plots}
\item \href{https://patchwork.data-imaginist.com/articles/guides/layout.html}{Defining Layouts}
\item \href{https://patchwork.data-imaginist.com/articles/guides/annotation.html}{Adding Annotation}
\item \href{https://patchwork.data-imaginist.com/articles/guides/multipage.html}{Aligning across pages}
}
}
\examples{
library(ggplot2)
# You can add plots saved to variables
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
p1 + p2
# Or build it up in one step
ggplot(mtcars) +
geom_point(aes(mpg, disp)) +
ggplot(mtcars) +
geom_boxplot(aes(gear, disp, group = gear))
}
\seealso{
Useful links:
\itemize{
\item \url{https://patchwork.data-imaginist.com}
\item \url{https://github.com/thomasp85/patchwork}
\item Report bugs at \url{https://github.com/thomasp85/patchwork/issues}
}
}
\author{
\strong{Maintainer}: Thomas Lin Pedersen \email{thomasp85@gmail.com} (\href{https://orcid.org/0000-0002-5147-4711}{ORCID})
}
\keyword{internal}
patchwork/man/patchworkGrob.Rd 0000644 0001762 0000144 00000001032 13564736727 016152 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot_patchwork.R
\name{patchworkGrob}
\alias{patchworkGrob}
\title{Convert a patchwork to a gtable}
\usage{
patchworkGrob(x)
}
\arguments{
\item{x}{A \code{patchwork} object}
}
\value{
A \code{gtable} object
}
\description{
This function is the patchwork analogue of \code{\link[ggplot2:ggplotGrob]{ggplot2::ggplotGrob()}} in that it
takes an unevaluated patchwork object and fixate it into a gtable object to
further manipulate directly.
}
\keyword{internal}
patchwork/man/wrap_ggplot_grob.Rd 0000644 0001762 0000144 00000002712 13567464644 016701 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/wrap_ggplot_grob.R
\name{wrap_ggplot_grob}
\alias{wrap_ggplot_grob}
\title{Make a gtable created from a ggplot object patchwork compliant}
\usage{
wrap_ggplot_grob(x)
}
\arguments{
\item{x}{A gtable as produced by \code{\link[ggplot2:ggplotGrob]{ggplot2::ggplotGrob()}}}
}
\value{
A \code{table_patch} object to be added to a patchwork
}
\description{
This function converts a gtable, as produced by \code{\link[ggplot2:ggplotGrob]{ggplot2::ggplotGrob()}} and
makes it ready to be added to a patchwork. In contrast to passing
the gtable to \code{\link[=wrap_elements]{wrap_elements()}}, \code{wrap_ggplot_grob()} ensures proper
alignment as expected. On the other hand major restructuring of the gtable
will result in an object that doesn't work properly with
\code{wrap_ggplot_grob()}.
}
\examples{
library(grid)
library(gtable)
library(ggplot2)
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) + ggtitle('disp and mpg seems connected')
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
# Convert p2 so we can add new stuff to it
p2_table <- ggplotGrob(p2)
stamp <- textGrob('TOP SECRET', rot = 35,
gp = gpar(fontsize = 72, fontface = 'bold')
)
p2_table <- gtable_add_grob(p2_table, stamp,
t = 1, l = 1, b = nrow(p2_table), r = ncol(p2_table)
)
# Adding it directly will loose alignment
p1 + p2_table
# Use wrap_ggplot_grob to keep alignment
p1 + wrap_ggplot_grob(p2_table)
}
patchwork/man/plot_layout.Rd 0000644 0001762 0000144 00000010757 14545740761 015720 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot_layout.R
\name{plot_layout}
\alias{plot_layout}
\title{Define the grid to compose plots in}
\usage{
plot_layout(
ncol = NULL,
nrow = NULL,
byrow = NULL,
widths = NULL,
heights = NULL,
guides = NULL,
tag_level = NULL,
design = NULL,
axes = NULL,
axis_titles = axes
)
}
\arguments{
\item{ncol, nrow}{The dimensions of the grid to create - if both are \code{NULL} it
will use the same logic as \link[ggplot2:facet_wrap]{facet_wrap()} to set the
dimensions}
\item{byrow}{Analogous to \code{byrow} in \link[base:matrix]{matrix()}. If \code{FALSE} the
plots will be filled in in column-major order}
\item{widths, heights}{The relative widths and heights of each column and row
in the grid. Will get repeated to match the dimensions of the grid. The
special value of \code{NA}/\verb{-1null} will behave as \verb{1null} unless a fixed aspect
plot is inserted in which case it will allow the dimension to expand or
contract to match the aspect ratio of the content}
\item{guides}{A string specifying how guides should be treated in the layout.
\code{'collect'} will collect guides below to the given nesting level, removing
duplicates. \code{'keep'} will stop collection at this level and let guides be
placed alongside their plot. \code{auto} will allow guides to be collected if a
upper level tries, but place them alongside the plot if not. If you modify
default guide "position" with \link[ggplot2:theme]{theme(legend.position=...)}
while also collecting guides you must apply that change to the overall
patchwork (see example).}
\item{tag_level}{A string (\code{'keep'} or \code{'new'}) to indicate how
auto-tagging should behave. See \code{\link[=plot_annotation]{plot_annotation()}}.}
\item{design}{Specification of the location of areas in the layout. Can either
be specified as a text string or by concatenating calls to \code{\link[=area]{area()}} together.
See the examples for further information on use.}
\item{axes}{A string specifying how axes should be treated. \code{'keep'} will
retain all axes in individual plots. \code{'collect'} will remove duplicated
axes when placed in the same run of rows or columns of the layout.
\code{'collect_x'} and \code{'collect_y'} will remove duplicated x-axes in the columns
or duplicated y-axes in the rows respectively.}
\item{axis_titles}{A string specifying how axis titltes should be treated.
\code{'keep'} will retain all axis titles in individual plots. \code{'collect'} will
remove duplicated titles in one direction and merge titles in the opposite
direction. \code{'collect_x'} and \code{'collect_y'} control this for x-axis titles
and y-axis titles respectively.}
}
\value{
A \code{plot_layout} object to be added to a \code{ggassmble} object
}
\description{
To control how different plots are laid out, you need to add a
layout specification. If you are nesting grids, the layout is scoped to the
current nesting level.
}
\examples{
library(ggplot2)
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)
p4 <- ggplot(mtcars) + geom_bar(aes(carb))
p5 <- ggplot(mtcars) + geom_violin(aes(cyl, mpg, group = cyl))
# The plots are layed out automatically by default
p1 + p2 + p3 + p4 + p5
# Use byrow to change how the grid is filled out
p1 + p2 + p3 + p4 + p5 + plot_layout(byrow = FALSE)
# Change the grid dimensions
p1 + p2 + p3 + p4 + p5 + plot_layout(ncol = 2, widths = c(1, 2))
# Define layout at different nesting levels
p1 +
p2 +
(p3 +
p4 +
plot_layout(ncol = 1)
) +
p5 +
plot_layout(widths = c(2, 1))
# Complex layouts can be created with the `design` argument
design <- c(
area(1, 1, 2),
area(1, 2, 1, 3),
area(2, 3, 3),
area(3, 1, 3, 2),
area(2, 2)
)
p1 + p2 + p3 + p4 + p5 + plot_layout(design = design)
\donttest{
# The same can be specified as a character string:
design <- "
122
153
443
"
p1 + p2 + p3 + p4 + p5 + plot_layout(design = design)
# When using strings to define the design `#` can be used to denote empty
# areas
design <- "
1##
123
##3
"
p1 + p2 + p3 + plot_layout(design = design)
}
# Use guides="collect" to remove duplicate guides
p6 <- ggplot(mtcars) + geom_point(aes(mpg, disp, color=cyl))
p7 <- ggplot(mtcars) + geom_point(aes(mpg, hp, color=cyl))
p6 + p7 + plot_layout(guides='collect')
# Guide position must be applied to entire patchwork
p6 + p7 + plot_layout(guides='collect') &
theme(legend.position='bottom')
}
patchwork/man/multipage_align.Rd 0000644 0001762 0000144 00000003740 13571014505 016464 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot_multipage.R
\name{multipage_align}
\alias{multipage_align}
\alias{get_dim}
\alias{set_dim}
\alias{get_max_dim}
\alias{align_patches}
\title{Align plots across multiple pages}
\usage{
get_dim(plot)
set_dim(plot, dim)
get_max_dim(...)
align_patches(...)
}
\arguments{
\item{plot}{A ggplot object}
\item{dim}{A plot_dimension object as created by \code{get_dim()}}
\item{...}{ggplot objects or a single list of them}
}
\value{
\code{get_dim()} and \code{get_max_dim()} return a plot_dimension object.
\code{set_dim()} returns a modified ggplot object with fixed outer dimensions and
\code{align_patches()} return a list of such. The modified ggplots still behaves
like a standard ggplot and new layers, scales, etc can be added to them.
}
\description{
Sometimes it is necessary to make sure that separate plots are aligned, with
each other, but still exists as separate plots. That could e.g. be if they
need to be part of a slideshow and you don't want titles and panels jumping
around as you switch between slides. patchwork provides a range of utilities
to achieve that. Currently it is only possible to align ggplots, but aligning
patchworks will be supported in the future.
}
\examples{
library(ggplot2)
p1 <- ggplot(mtcars) +
geom_point(aes(mpg, disp)) +
ggtitle('Plot 1')
p2 <- ggplot(mtcars) +
geom_boxplot(aes(gear, disp, group = gear)) +
ggtitle('Plot 2')
p3 <- ggplot(mtcars) +
geom_point(aes(hp, wt, colour = mpg)) +
ggtitle('Plot 3')
p4 <- ggplot(mtcars) +
geom_bar(aes(gear)) +
facet_wrap(~cyl) +
ggtitle('Plot 4')
# Align a plot to p4
p4_dim <- get_dim(p4)
set_dim(p1, p4_dim)
# Align a plot to the maximum dimensions of a list of plots
max_dims <- get_max_dim(p1, p2, p3, p4)
set_dim(p2, max_dims)
# Align a list of plots with each other
aligned_plots <- align_patches(p1, p2, p3, p4)
aligned_plots[[3]]
# Aligned plots still behave like regular ggplots
aligned_plots[[3]] + theme_bw()
}
patchwork/man/plot_spacer.Rd 0000644 0001762 0000144 00000001603 14277442534 015645 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot_spacer.R
\name{plot_spacer}
\alias{plot_spacer}
\title{Add a completely blank area}
\usage{
plot_spacer()
}
\value{
A \code{ggplot} object containing an empty plot
}
\description{
This simple wrapper creates an empty transparent patch that can be added to
push your other plots apart. The patch responds to adding
\link[ggplot2:theme]{theme()} specifications, but only \code{plot.background} will
have an effect.
}
\examples{
library(ggplot2)
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
p1 + plot_spacer() + p2
# To have more control over spacing, you can use the `plot.margin`
# parameter for `theme()` on each individual plot.
(p1 + theme(plot.margin = unit(c(0,30,0,0), "pt"))) +
(p2 + theme(plot.margin = unit(c(0,0,0,30), "pt")))
}
patchwork/man/align_plots.Rd 0000644 0001762 0000144 00000000375 13571015322 015635 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot_multipage.R
\name{align_plots}
\alias{align_plots}
\title{Deprecated functions}
\description{
These functions are deprecated and should not be used.
}
\keyword{internal}
patchwork/man/guide_area.Rd 0000644 0001762 0000144 00000002312 13567470054 015414 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/guide_area.R
\name{guide_area}
\alias{guide_area}
\title{Add an area to hold collected guides}
\usage{
guide_area()
}
\description{
Using the \code{guides} argument in \code{\link[=plot_layout]{plot_layout()}} you can collect and collapse
guides from plots. By default these guides will be put on the side like with
regular plots, but by adding a \code{guide_area()} to the plot you can tell
patchwork to place the guides in that area instead. If guides are not
collected or no guides exists to collect it behaves as a standard
\code{\link[=plot_spacer]{plot_spacer()}} instead.
}
\examples{
library(ggplot2)
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)
# Guides are by default kept beeside their plot
p1 + p2 + p3
# They can be collected and placed on the side (according to the patchwork
# theme)
p1 + p2 + p3 + plot_layout(guides = 'collect', ncol = 2)
# Using guide_area() you can also designate an empty area for this
p1 + p2 + p3 + guide_area() + plot_layout(guides = 'collect')
}
patchwork/man/free.Rd 0000644 0001762 0000144 00000003505 14545734301 014250 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/free.R
\name{free}
\alias{free}
\title{Free a plot from alignment}
\usage{
free(x)
}
\arguments{
\item{x}{A ggplot or patchwork object}
}
\value{
A modified version of \code{x} with a \code{free_plot} class
}
\description{
While the purpose of patchwork is often to align plots by their panels,
sometimes this doesn't cut it and we want to compose plots without alignment.
The \code{free()} function tells patchwork to treat the content (which can either
be a ggplot or a patchwork) specially and not align it with the remaining
panels in the composition. It works much like using \code{\link[=wrap_elements]{wrap_elements()}} but has
a few niceties. For starter, it is less verbose, both with a shorter name,
but also without the need to use the \code{full} argument rather than the first.
Second, A plot wrapped with \code{free()} retains all of it's behavior from
before. You can still add stuff to it, change it's theme, etc., but more
importantly you can still collect guides and recurse tags as usual. A further
nicety is that margins of the plot behave as expected and is aligned with the
other plots in the composition.
}
\examples{
# Sometimes you have a plot that defies good composition alginment, e.g. due
# to long axis labels
library(ggplot2)
p1 <- ggplot(mtcars) +
geom_bar(aes(y = factor(gear), fill = factor(gear))) +
scale_y_discrete(
"",
labels = c("3 gears are often enough",
"But, you know, 4 is a nice number",
"I would def go with 5 gears in a modern car")
)
# When combined with other plots it ends up looking bad
p2 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p1 / p2
# We can fix this be using free
free(p1) / p2
# We can still collect guides like before
free(p1) / p2 + plot_layout(guides = "collect")
}
patchwork/man/figures/ 0000755 0001762 0000144 00000000000 14545740746 014513 5 ustar ligges users patchwork/man/figures/README-unnamed-chunk-7-1.png 0000644 0001762 0000144 00000124314 13565477507 021223 0 ustar ligges users PNG
IHDR z4 iCCPkCGColorSpaceGenericRGB 8U]hU>sg#$Sl4t?
%
V46nI6"dΘ83OEP|1Ŀ (>/
% (>P苦;3ie|{g蹪X-2s=+WQ+]L6Ow[C{_F qbUvz?Zb1@/zcs>~if,ӈUSjF1_Mjbuݠpamhmçϙ>a\+5%QKFkm}ۖ?ޚD\!~6,-7SثŜvķ5Z;[rmS5{yDyH}r9|-ăFAJjI.[/]mK7KRDrYQO-Q||6
(0
MXd(@h2_f<:_δ*d>e\c?~,7?& ك^2Iq2"y