diff --git a/404.html b/404.html index 58940cf..f77a5ba 100644 --- a/404.html +++ b/404.html @@ -27,7 +27,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/CODE_OF_CONDUCT.html b/CODE_OF_CONDUCT.html index 89b70e6..b9399f5 100644 --- a/CODE_OF_CONDUCT.html +++ b/CODE_OF_CONDUCT.html @@ -7,7 +7,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/LICENSE-text.html b/LICENSE-text.html index aff7ff8..9997368 100644 --- a/LICENSE-text.html +++ b/LICENSE-text.html @@ -7,7 +7,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/articles/guides/annotation.html b/articles/guides/annotation.html index a2f7858..fd25165 100644 --- a/articles/guides/annotation.html +++ b/articles/guides/annotation.html @@ -26,7 +26,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/articles/guides/assembly.html b/articles/guides/assembly.html index 031dd25..8d077c7 100644 --- a/articles/guides/assembly.html +++ b/articles/guides/assembly.html @@ -26,7 +26,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/articles/guides/layout.html b/articles/guides/layout.html index dd435e9..28268a3 100644 --- a/articles/guides/layout.html +++ b/articles/guides/layout.html @@ -26,7 +26,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/articles/guides/multipage.html b/articles/guides/multipage.html index 3af39db..8a5fc17 100644 --- a/articles/guides/multipage.html +++ b/articles/guides/multipage.html @@ -26,7 +26,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/articles/index.html b/articles/index.html index 06fe850..809afa8 100644 --- a/articles/index.html +++ b/articles/index.html @@ -7,7 +7,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/articles/patchwork.html b/articles/patchwork.html index afd6d69..e7528a5 100644 --- a/articles/patchwork.html +++ b/articles/patchwork.html @@ -26,7 +26,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/authors.html b/authors.html index e9b8119..ee6a7f9 100644 --- a/authors.html +++ b/authors.html @@ -7,7 +7,7 @@ patchwork - 1.2.0.9000 + 1.3.0 @@ -61,13 +61,13 @@ Citation Pedersen T (2024). patchwork: The Composer of Plots. -R package version 1.2.0.9000, https://github.com/thomasp85/patchwork, https://patchwork.data-imaginist.com. +R package version 1.3.0, https://github.com/thomasp85/patchwork, https://patchwork.data-imaginist.com. @Manual{, title = {patchwork: The Composer of Plots}, author = {Thomas Lin Pedersen}, year = {2024}, - note = {R package version 1.2.0.9000, https://github.com/thomasp85/patchwork}, + note = {R package version 1.3.0, https://github.com/thomasp85/patchwork}, url = {https://patchwork.data-imaginist.com}, } diff --git a/index.html b/index.html index fd08b33..7ad082d 100644 --- a/index.html +++ b/index.html @@ -29,7 +29,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/news/index.html b/news/index.html index fcfd14d..22d06c6 100644 --- a/news/index.html +++ b/news/index.html @@ -7,7 +7,7 @@ patchwork - 1.2.0.9000 + 1.3.0 @@ -48,7 +48,7 @@ -patchwork (development version) +patchwork 1.3.0CRAN release: 2024-09-16 free() now better aligns plots in horizontal direction Plot backgrounds are now always placed beneath all other elements in the patchwork (#370) diff --git a/pkgdown.yml b/pkgdown.yml index e8cfbb0..b540ff5 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -7,7 +7,7 @@ articles: guides/layout: guides/layout.html guides/multipage: guides/multipage.html patchwork: patchwork.html -last_built: 2024-09-16T08:15Z +last_built: 2024-09-16T10:11Z urls: reference: https://patchwork.data-imaginist.com/reference article: https://patchwork.data-imaginist.com/articles diff --git a/reference/align_plots.html b/reference/align_plots.html index 872e2ea..13b9ac1 100644 --- a/reference/align_plots.html +++ b/reference/align_plots.html @@ -7,7 +7,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/area.html b/reference/area.html index 0507e91..0e6bf2a 100644 --- a/reference/area.html +++ b/reference/area.html @@ -11,7 +11,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/free.html b/reference/free.html index 9e7b829..5a45ef8 100644 --- a/reference/free.html +++ b/reference/free.html @@ -23,7 +23,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/guide_area.html b/reference/guide_area.html index fdece96..5aeef8d 100644 --- a/reference/guide_area.html +++ b/reference/guide_area.html @@ -17,7 +17,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/index.html b/reference/index.html index a59a35c..488e1f3 100644 --- a/reference/index.html +++ b/reference/index.html @@ -7,7 +7,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/inset_element.html b/reference/inset_element.html index 9290779..64910d0 100644 --- a/reference/inset_element.html +++ b/reference/inset_element.html @@ -15,7 +15,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/multipage_align.html b/reference/multipage_align.html index 5f45bff..f3b1168 100644 --- a/reference/multipage_align.html +++ b/reference/multipage_align.html @@ -17,7 +17,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/patchGrob.html b/reference/patchGrob.html index d2ad94a..2715161 100644 --- a/reference/patchGrob.html +++ b/reference/patchGrob.html @@ -15,7 +15,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/patchwork-package.html b/reference/patchwork-package.html index 64c6a5e..20a4e89 100644 --- a/reference/patchwork-package.html +++ b/reference/patchwork-package.html @@ -9,7 +9,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/patchworkGrob.html b/reference/patchworkGrob.html index 48e5dc1..900f32c 100644 --- a/reference/patchworkGrob.html +++ b/reference/patchworkGrob.html @@ -11,7 +11,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/plot_annotation.html b/reference/plot_annotation.html index 21ef267..6e3fe7c 100644 --- a/reference/plot_annotation.html +++ b/reference/plot_annotation.html @@ -15,7 +15,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/plot_arithmetic.html b/reference/plot_arithmetic.html index e7f05e3..fe28af9 100644 --- a/reference/plot_arithmetic.html +++ b/reference/plot_arithmetic.html @@ -11,7 +11,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/plot_layout.html b/reference/plot_layout.html index f5f9d32..ba7d254 100644 --- a/reference/plot_layout.html +++ b/reference/plot_layout.html @@ -13,7 +13,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/plot_spacer.html b/reference/plot_spacer.html index e44ee93..ca3d022 100644 --- a/reference/plot_spacer.html +++ b/reference/plot_spacer.html @@ -13,7 +13,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/wrap_elements.html b/reference/wrap_elements.html index 56e8d99..6176d51 100644 --- a/reference/wrap_elements.html +++ b/reference/wrap_elements.html @@ -35,7 +35,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/wrap_ggplot_grob.html b/reference/wrap_ggplot_grob.html index 9f34a8f..9f3cfb7 100644 --- a/reference/wrap_ggplot_grob.html +++ b/reference/wrap_ggplot_grob.html @@ -17,7 +17,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/wrap_plots.html b/reference/wrap_plots.html index d06259d..ab189b0 100644 --- a/reference/wrap_plots.html +++ b/reference/wrap_plots.html @@ -13,7 +13,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/reference/wrap_table.html b/reference/wrap_table.html index dff581a..9d02865 100644 --- a/reference/wrap_table.html +++ b/reference/wrap_table.html @@ -15,7 +15,7 @@ patchwork - 1.2.0.9000 + 1.3.0 diff --git a/search.json b/search.json index 8eb6c11..b32affd 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"path":"https://patchwork.data-imaginist.com/CODE_OF_CONDUCT.html","id":null,"dir":"","previous_headings":"","what":"Contributor Code of Conduct","title":"Contributor Code of Conduct","text":"contributors maintainers project, pledge respect people contribute reporting issues, posting feature requests, updating documentation, submitting pull requests patches, activities. committed making participation project harassment-free experience everyone, regardless level experience, gender, gender identity expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion. Examples unacceptable behavior participants include use sexual language imagery, derogatory comments personal attacks, trolling, public private harassment, insults, unprofessional conduct. Project maintainers right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct. Project maintainers follow Code Conduct may removed project team. Instances abusive, harassing, otherwise unacceptable behavior may reported opening issue contacting one project maintainers. Code Conduct adapted Contributor Covenant (https://www.contributor-covenant.org), version 1.0.0, available https://contributor-covenant.org/version/1/0/0/.","code":""},{"path":"https://patchwork.data-imaginist.com/articles/guides/annotation.html","id":"titles-subtitles-and-captions","dir":"Articles > Guides","previous_headings":"","what":"Titles, subtitles and captions","title":"Adding Annotation and Style","text":"One needed things add descriptive text plot ensemble. achieve , simply add patchwork using plot_annotation() important note plot annotations effect top-level patchwork. annotation added nested patchworks (currently) lost. need annotations nested patchwork ’ll need wrap wrap_elements() side-effect alignment longer works.","code":"patchwork <- (p1 + p2) / p3 patchwork + plot_annotation( title = 'The surprising truth about mtcars', subtitle = 'These 3 plots will reveal yet-untold secrets about our beloved data-set', caption = 'Disclaimer: None of these plots are insightful' )"},{"path":"https://patchwork.data-imaginist.com/articles/guides/annotation.html","id":"tagging","dir":"Articles > Guides","previous_headings":"","what":"Tagging","title":"Adding Annotation and Style","text":"Often, especially scientific literature, multiple plots collected single figure referred tag. tags added manually, much simpler let patchwork handle , using auto-tagging functionality. turned setting tag_level plot_annotation() value indicating family symbols use tagging: '1' Arabic numerals, '' uppercase Latin letters, '' lowercase Latin letters, '' uppercase Roman numerals, '' lowercase Roman numerals. Tags uses theming plot applied , make sure match , modify theming plots using & (see Plot Assembly guide). patchwork contains nested layouts tagging recurse default, can tell define new tagging level tag_level argument plot_layout(). can provide multiple tag-types tag_levels define subtagging enumerated. plot_annotation()also possible define separator, prefix, suffix tag, don’t go overboard : default ggplot2 theme puts tag row column expand fit. longer tag text look weird, better place top plot region: Lastly also possible provide tag sequence instead relying build ones. Passing list character vectors just (note can mixed standard sequences): provide plots custom sequence support excess plots get empty tags make sure ’s enough.","code":"patchwork + plot_annotation(tag_levels = 'A') patchwork + plot_annotation(tag_levels = 'A') & theme(plot.tag = element_text(size = 8)) patchwork[[1]] <- patchwork[[1]] + plot_layout(tag_level = 'new') patchwork + plot_annotation(tag_levels = c('A', '1')) patchwork + plot_annotation(tag_levels = c('A', '1'), tag_prefix = 'Fig. ', tag_sep = '.', tag_suffix = ':') patchwork + plot_annotation(tag_levels = c('A', '1'), tag_prefix = 'Fig. ', tag_sep = '.', tag_suffix = ':') & theme(plot.tag.position = c(0, 1), plot.tag = element_text(size = 8, hjust = 0, vjust = 0)) patchwork + plot_annotation(tag_levels = list(c('#', '&'), '1'))"},{"path":"https://patchwork.data-imaginist.com/articles/guides/annotation.html","id":"styling-the-patchwork","dir":"Articles > Guides","previous_headings":"","what":"Styling the patchwork","title":"Adding Annotation and Style","text":"style patchwork made themes individual patches. coherent look, don’t mix widely different looks. Setting background colour single plot different shade effective way highlight , e.g. different fonts line widths just look like mess. patchwork elements susceptible theming: background, margin, title, subtitle & caption. theme patchwork default default ggplot2 theme. can changed though, two different ways. easiest simply use & theme element. operator add theme subplots well theme patchwork : need address theme patchwork (e.g. making patchwork title larger plot titles), can done theme argument plot_annotation() (note use one exclude ):","code":"patchwork + plot_annotation(title = 'The surprising truth about mtcars') & theme(text = element_text('mono')) patchwork + plot_annotation(title = 'The surprising truth about mtcars', theme = theme(plot.title = element_text(size = 18))) & theme(text = element_text('mono'))"},{"path":"https://patchwork.data-imaginist.com/articles/guides/annotation.html","id":"want-more","dir":"Articles > Guides","previous_headings":"","what":"Want more?","title":"Adding Annotation and Style","text":"Now know annotate style patchwork. Read guides assembling laying patchwork master patchwork.","code":""},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"adding-plots-to-the-patchwork","dir":"Articles > Guides","previous_headings":"","what":"Adding plots to the patchwork","title":"Plot Assembly","text":"point, shouldn’t come surprise can use + add plots together form patchwork. , ’d suggest start Getting Started guide, come back ’ve gone . , just recap: can add plots together, like : Using approach, possible assemble number plots, thing can added. patchworks can added, create new nested patchwork:","code":"p1 + p2 patch <- p1 + p2 p3 + patch"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"adding-tables","dir":"Articles > Guides","previous_headings":"Adding plots to the patchwork","what":"Adding tables","title":"Plot Assembly","text":"patchwork deep support working tables powered gt package provides means define align panel region well whether respect table size setting size rows columns patchwork. just want standard settings can add gt table directly plot want change settings wrap wrap_table() function. force table headers inside panel region sets sizing space table occupies based actual size table (note, using wrap_table() can pass data.frame directly)","code":"p1 + gt::gt(mtcars[1:10, c('mpg', 'disp')]) p1 + wrap_table(mtcars[1:10, c('mpg', 'disp')], panel = \"full\", space = \"fixed\")"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"adding-other-content","dir":"Articles > Guides","previous_headings":"Adding plots to the patchwork","what":"Adding other content","title":"Plot Assembly","text":"Sometimes need content ggplot2 patchwork. Standard grid grobs can added plot well: packages might provide even elaborate grob specifications can likewise added directly. Now , necessary work plots graphics package (base graphics). can added patchwork providing one-sided formula: Notice standard alignment ’d expect adding ggplots together longer works. general, way get consistent alignment ggplots base graphics, experiment different par() settings get something works particular use-case. ggplotify package provides even functionality converting different graphics grobs standard formula interface patchwork doesn’t work , check . workhorse underneath ability add non-ggplot objects patchwork wrap_elements() called implicitly adding non-ggplot objects. get bit control object added, wrap object directly wrap_elements(). can define object aligned full area, plot area. Combining setting margins zero clipping grob, can almost get perfect alignment: interesting side effect setup possible add labels styling wrapped element (though theme settings ignored). can come pretty close aligned base plot, always bit fiddly ad hoc. general simply recommended use ggplot2 possible. Another use case wrap_elements() need first plot ggplot. Patchwork able change + behavior miscellaneous objects, , appear first element must wrapped object patchwork understands:","code":"p1 + grid::textGrob('Some really important text') p1 + ~plot(mtcars$mpg, mtcars$disp, main = 'Plot 2') old_par <- par(mar = c(0, 2, 0, 0), bg = NA) p1 + wrap_elements(panel = ~plot(mtcars$mpg, mtcars$disp), clip = FALSE) par(old_par) old_par <- par(mar = c(0, 0, 0, 0), mgp = c(1, 0.25, 0), bg = NA, cex.axis = 0.75, las = 1, tcl = -0.25) p1 + wrap_elements(panel = ~plot(mtcars$mpg, mtcars$disp), clip = FALSE) + ggtitle('Plot 2') + theme(plot.margin = margin(5.5, 5.5, 5.5, 35)) par(old_par) # This won't do anything grid::textGrob('Text on left side') + p1 #> NULL # This will work wrap_elements(grid::textGrob('Text on left side')) + p1"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"stacking-and-packing","dir":"Articles > Guides","previous_headings":"Adding plots to the patchwork","what":"Stacking and packing","title":"Plot Assembly","text":"+ operator simply combines plots without telling patchwork anything desired layout. layout, unless changed plot_layout() (See Controlling Layout guide), simply grid enough rows columns contain number plots, square possible. special case putting plots besides top patchwork provides 2 shortcut operators. | place plots next / place top . 3 plots | behave just + using | communicate intend layout better. aware mixing operators put control operator precedence rule (e.g. / evaluated +). always good idea put sub-assemblies within braces avoid surprises:","code":"p1 / p2 p1 | p2 p1 / (p2 | p3)"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"functional-assembly","dir":"Articles > Guides","previous_headings":"Adding plots to the patchwork","what":"Functional assembly","title":"Plot Assembly","text":"using different operators provides clean API assembly, less suited situations control plot-generation process. handed list plot objects want assemble patchwork bit clumsy using + operator (doable loop Reduce()). patchwork provides wrap_plots() functional approach assembly. takes either separate plots list adds single patchwork. top also accepts arguments plot_layout() (see Controlling Layouts guide) can used single solution assembly needs:","code":"wrap_plots(p1, p2, p3, p4)"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"nesting-the-left-hand-side","dir":"Articles > Guides","previous_headings":"","what":"Nesting the left-hand side","title":"Plot Assembly","text":"plots always added patchwork left-hand side, possible nest left-hand side beside right-hand side standard operators shown . can lead surprising behavior: nest right-hand side, true left-hand side behavior necessary allow patchworks build gradually, get way left-hand side nested. patchwork provides - operator exact situation. conceptually understood hyphen minus, keeps side (puts nesting level): alternative - use merge() left hand side thing. Using approach possible use combination / | option using -. Yet another way solve wrap_plots(), put input nesting level, irrespective order:","code":"patch <- p1 + p2 p3 + patch patch + p3 patch - p3 wrap_plots(patch, p3)"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"modifying-patches","dir":"Articles > Guides","previous_headings":"","what":"Modifying patches","title":"Plot Assembly","text":"creating patchwork, resulting object remain ggplot object referencing last added plot. means can continue add objects geoms, scales, etc. normal ggplot: need modify another patch patchwork can access /modify double-bracket indexing. useful work function returns patchwork want modify one subplots:","code":"p1 + p2 + geom_jitter(aes(gear, disp)) patchwork <- p1 + p2 patchwork[[1]] <- patchwork[[1]] + theme_minimal() patchwork"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"modifying-everything","dir":"Articles > Guides","previous_headings":"Modifying patches","what":"Modifying everything","title":"Plot Assembly","text":"Often, especially comes theming, want modify everything . patchwork provides two additional operators facilitates . & add element subplots patchwork, * add element subplots current nesting level. | /, aware operator precedence must kept mind.","code":"patchwork <- p3 / (p1 | p2) patchwork & theme_minimal() patchwork * theme_minimal()"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"want-more","dir":"Articles > Guides","previous_headings":"","what":"Want more?","title":"Plot Assembly","text":"everything know combining modifying patches patchwork. sure check guides controlling layouts annotations.","code":""},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"adding-an-empty-area","dir":"Articles > Guides","previous_headings":"","what":"Adding an empty area","title":"Controlling Layouts","text":"Sometimes needed empty area plots. can done adding plot_spacer(). occupy grid cell way plot without outer elements (titles, ticks, strips, etc.): important understand added area corresponds size plot panel. means spacers separate nesting levels may different dimensions:","code":"p1 + plot_spacer() + p2 + plot_spacer() + p3 + plot_spacer() (p1 + plot_spacer() + p2) / (plot_spacer() + p3 + plot_spacer())"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"controlling-the-grid","dir":"Articles > Guides","previous_headings":"","what":"Controlling the grid","title":"Controlling Layouts","text":"nothing given, patchwork try make grid square possible, erring side horizontal grid square possible (uses heuristic facet_wrap() ggplot2). , column row grid take space. can controlled plot_layout() grid sizes given numeric, define relative sizing panels. , panel area first column twice second column. also possible supply unit vector instead: last example first row always occupy 5cm, second expand fill remaining area. important remember sizing affects plotting region (panel area). plot , e.g., wide y-axis text penalized get smaller overall plotting region.","code":"p1 + p2 + p3 + p4 + plot_layout(ncol = 3) p1 + p2 + p3 + p4 + plot_layout(widths = c(2, 1)) p1 + p2 + p3 + p4 + plot_layout(widths = c(2, 1), heights = unit(c(5, 1), c('cm', 'null')))"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"moving-beyond-the-grid","dir":"Articles > Guides","previous_headings":"","what":"Moving beyond the grid","title":"Controlling Layouts","text":"Earlier, ’ve wanted create non-grid compositions, ’ve used nesting. often enough, end losing alignment subplots different nested areas. alternative define layout design fill plots . design can defined two different ways. easiest use textual representation: using textual representation responsibility make sure area rectangular. exception # denotes empty areas can thus shape. programmatic approach build layout using area() constructor. bit verbose easier program . , allows overlay plots. design specification can course also used widths heights specify size columns rows design. small additional feature design argument exists used conjunction wrap_plots() function (See Plot Assembly guide). design given textual representation, can name plots match different areas, instead letting filled order appear:","code":"layout <- \" ##BBBB AACCDD ##CCDD \" p1 + p2 + p3 + p4 + plot_layout(design = layout) layout <- c( area(t = 2, l = 1, b = 5, r = 4), area(t = 1, l = 3, b = 3, r = 5) ) p1 + p2 + plot_layout(design = layout) layout <- ' A#B #C# D#E ' wrap_plots(D = p1, C = p2, B = p3, design = layout)"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"fixed-aspect-plots","dir":"Articles > Guides","previous_headings":"","what":"Fixed aspect plots","title":"Controlling Layouts","text":"special case comes assembling plots dealing fixed aspect plots, created coord_fixed(), coord_polar(), coord_sf(). possible simultaneously assign even dimensions align fixed aspect plots. default value widths heights arguments plot_layout() NA, treated specially. general behave just 1null (.e. expand fill available space share evenly 1null panels), row/column occupied fixed aspect plot expand contract order keep aspect plot may thus dimension grid width/heights containing plots without fixed aspect plots. need mix behavior fixed dimensions can use special value -1null behaves NA (unit vectors doesn’t allow NA values). width = unit(c(1, 3, -1), c(\"null\", \"cm\", \"null\") specify one column fills available space, one column fixed 3 cm, one column expands match fixed aspect ratio needed otherwise takes size first column. Contrast setting widths non-NA value: can see, fixed aspect plot keeps aspect ratio, loses axis alignment one directions. solution needed probably dependent specific use case. default optimizes use space. restrictions space optimization. fixed aspect plot take multiple rows columns, one fixed aspect plot conflicts another one, one end using full space.","code":"p_fixed <- ggplot(mtcars) + geom_point(aes(hp, disp)) + ggtitle('Plot F') + coord_fixed() p_fixed + p1 + p2 + p3 p_fixed + p1 + p2 + p3 + plot_layout(widths = 1)"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"avoiding-alignment","dir":"Articles > Guides","previous_headings":"","what":"Avoiding alignment","title":"Controlling Layouts","text":"Patchwork designed ’s utmost align plotting areas, generally sensible order create calm good looking layout sometimes gets way creating want. see two cases. situation answer wrap_elements() function.","code":""},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"huge-axis-text-causing-white-space-","dir":"Articles > Guides","previous_headings":"Avoiding alignment","what":"Huge axis text causing white space.","title":"Controlling Layouts","text":"Sometimes one plots much longer axis text axis labels : Depending prefer might want leftmost plot fill much room possible instead aligned rightmost panel. Putting ggplot patchwork inside free() removes alignment plot.","code":"p2mod <- p2 + labs(x = \"This is such a long\\nand important label that\\nit has to span many lines\") p1 | p2mod free(p1) | p2mod"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"designs-dont-keep-an-even-width","dir":"Articles > Guides","previous_headings":"Avoiding alignment","what":"Designs don’t keep an even width","title":"Controlling Layouts","text":"creating complex layout using design may create setups plots spans edge plots surprised affects width panels design: see 3 bottom columns different widths despite given amount space design matrix. reason top plot y-axis left guide right, fall two columns make 1st 3rd column bottom. Subsequently plots expanded fill space. free() save us :","code":"design <- \"#AAAA# #AAAA# BBCCDD EEFFGG\" p3 + p2 + p1 + p4 + p4 + p1 + p2 + plot_layout(design = design) free(p3) + p2 + p1 + p4 + p4 + p1 + p2 + plot_layout(design = design)"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"more-freeing","dir":"Articles > Guides","previous_headings":"Avoiding alignment","what":"More freeing","title":"Controlling Layouts","text":"free() just un-align whole panel. can use side argument control sides align. instruct patchwork free left side ridiculous amount significant digits, keep remaining sides aligned free() also two modes besides default. One free alignment axis labels stick axis: free content outside panel claiming space. instance, plot, need top plot claim space ’s wide y-axis lot empty space left: Using type = \"space\" fix :","code":"p3_very_precise <- p3 + scale_y_continuous(labels = \\(x) format(as.numeric(x), nsmall = 10)) p1 / free(p3_very_precise, side = \"l\") free(p1, type = \"label\") / p3_very_precise plot_spacer() + p3_very_precise + p1 + p2 plot_spacer() + free(p3_very_precise, type = \"space\", side = \"l\") + p1 + p2"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"insets","dir":"Articles > Guides","previous_headings":"","what":"Insets","title":"Controlling Layouts","text":"alternative placing plots grid place plot inset another plot. saw , achievable setting layout multiple overlapping area() specifications. However, approach still uses underlying grid, may constraining. Another approach use inset_element() function marks plot graphic object placed inset previous plot. thus take slot provided layout, share slot previous plot. inset_element() allows freely position inset relative either panel, plot, full area previous plot, specifying location left, bottom, right, top edge inset. location can specified either numerics like grid units. specified numerics converted 'npc' units goes 0 1 specified area. example place inset exactly 1 cm panel border code : , inset_element() allows place inset previous plot, choose , controlling clipping tagging way wrap_elements().","code":"p1 + inset_element(p2, left = 0.6, bottom = 0.6, right = 1, top = 1) p1 + inset_element(p2, left = 0, bottom = 0.6, right = 0.4, top = 1, align_to = 'full') p1 + inset_element( p2, left = 0.5, bottom = 0.5, right = unit(1, 'npc') - unit(1, 'cm'), top = unit(1, 'npc') - unit(1, 'cm') ) p3 + inset_element(p1, left = 0.5, bottom = 0, right = 1, top = 0.5, on_top = FALSE, align_to = 'full')"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"controlling-guides","dir":"Articles > Guides","previous_headings":"","what":"Controlling guides","title":"Controlling Layouts","text":"Plots often guides help viewers deduce aesthetic mapping. composing plots need think . default behavior leave alone simply let follow plot around. Examples can seen color guide always positioned beside Plot 3. behavior fine purpose simply position bunch otherwise unrelated plots next . purpose composition create new tightly coupled visualization, presence guides plots can jarring, though. plot_layout() function provides guides argument controls guides treated. show works, let’s see happens set 'collect': can see guide hoisted placed beside plots. alternative 'collect' 'keep', makes sure guides kept next plot. default value 'auto', sort . collect guides, patchwork nested inside another patchwork patchwork collect guides, allowed hoist . see effect, compare two plots: guide collection another trick sleeve. multiple plots provide guide, don’t want show multiple times. collecting guides compare remove duplicates. Guides compared graphical representation, declarative specification. means different theming among plots may mean two guides showing information merged. Now end empty area grid. Instead leaving empty, can specify place put collected guides, using guide_area() placeholder. works much plot_spacer(), guides collected exactly . guides collected placed instead theme tells . Guide areas accessible nesting level. nested patchwork guide area possible place guides collected higher level .","code":"p1 + p2 + p3 + p4 + plot_layout(guides = 'collect') ((p2 / p3 + plot_layout(guides = 'auto')) | p1) + plot_layout(guides = 'collect') ((p2 / p3 + plot_layout(guides = 'keep')) | p1) + plot_layout(guides = 'collect') p1a <- ggplot(mtcars) + geom_point(aes(mpg, disp, colour = mpg, size = wt)) + ggtitle('Plot 1a') p1a | (p2 / p3) (p1a | (p2 / p3)) + plot_layout(guides = 'collect') p1 + p2 + p3 + guide_area() + plot_layout(guides = 'collect')"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"controlling-axes","dir":"Articles > Guides","previous_headings":"","what":"Controlling Axes","title":"Controlling Layouts","text":"Much like legends , axes can sometimes shared plots. However, makes sense plots positioned besides top exact axis. patchwork provides two arguments plot_layout() controlling axes work much like guides argument except don’t allow recursing nested patchworks (obvious reasons). plot y-axis redundant kept side like used faceted plots: easily fixed axes argument default axis title follows collecting setting axis. also collect titles makes lot sense axes doesn’t match exactly still share title. , title collecting also work direction: see y-axis title now appears positioned centrally.","code":"p1 + p2 p1 + p2 + plot_layout(axes = \"collect\") p1 + p2 + plot_layout(axis_titles = \"collect\") p1 / p2 + plot_layout(axis_titles = \"collect\")"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"want-more","dir":"Articles > Guides","previous_headings":"","what":"Want more?","title":"Controlling Layouts","text":"layouts. still patchwork. Explore guides learn annotations, special operators multipage alignment.","code":""},{"path":"https://patchwork.data-imaginist.com/articles/guides/multipage.html","id":"want-more","dir":"Articles > Guides","previous_headings":"","what":"Want more?","title":"Alignment Across Multiple Pages","text":"Multipage alignment just small part patchwork. Check guides learn assembling plots, specifying layouts, annotating results.","code":""},{"path":"https://patchwork.data-imaginist.com/articles/patchwork.html","id":"example-plots","dir":"Articles","previous_headings":"","what":"Example plots","title":"Getting Started","text":"’ll start creating example plots use throughout tutorial: plots fairly meaningless serve illustrate plot composition - don’t read anything resulting plots.","code":"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')"},{"path":"https://patchwork.data-imaginist.com/articles/patchwork.html","id":"basic-use","dir":"Articles","previous_headings":"","what":"Basic use","title":"Getting Started","text":"absolute simplest use extension + operator used ggplot2, allow adding plots together: adding plots together, last added plot active one, receive addition new ggplot2 objects geoms, labels, etc:","code":"p1 + p2 p1 + p2 + labs(subtitle = 'This will appear in the last plot')"},{"path":"https://patchwork.data-imaginist.com/articles/patchwork.html","id":"controlling-layout","dir":"Articles","previous_headings":"","what":"Controlling layout","title":"Getting Started","text":"default, patchwork try keep grid square, fill row order can controlled addition plot_layout() plot_layout() sorts amazing features controlling layout composition. See Layout vignette full rundown options.","code":"p1 + p2 + p3 + p4 p1 + p2 + p3 + p4 + plot_layout(nrow = 3, byrow = FALSE)"},{"path":"https://patchwork.data-imaginist.com/articles/patchwork.html","id":"stacking-and-packing-plots","dir":"Articles","previous_headings":"","what":"Stacking and packing plots","title":"Getting Started","text":"Often want place plots top , beside , rather fill grid. can accomplished adding one-row one-column layout, patchwork also provides two operators directly provides visual cues layout. | place plots beside , / stack : patchworks can nested, two operators often enough create rather complex layouts:","code":"p1 / p2 p1 | (p2 / p3)"},{"path":"https://patchwork.data-imaginist.com/articles/patchwork.html","id":"annotating-the-composition","dir":"Articles","previous_headings":"","what":"Annotating the composition","title":"Getting Started","text":"often necessary add titles, captions, tags, etc. composition. can achieved adding plot_annotation() patchwork: Patchwork also provides auto-tagging capabilities, order identify subplots text: tagging can either arabic roman numbers, latin letters, separate tags can given different nesting levels. See Annotation vignette information.","code":"(p1 | (p2 / p3)) + plot_annotation(title = 'The surprising story about mtcars') p1 + p2 + p3 + plot_annotation(tag_levels = 'I')"},{"path":"https://patchwork.data-imaginist.com/articles/patchwork.html","id":"want-more","dir":"Articles","previous_headings":"","what":"Want more?","title":"Getting Started","text":"enough get started, scratched surface patchwork capable . Look guides find , e.g. collect legends one place remove duplicates aligning plots across multiple pages.","code":""},{"path":"https://patchwork.data-imaginist.com/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Thomas Lin Pedersen. Maintainer, author.","code":""},{"path":"https://patchwork.data-imaginist.com/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Pedersen T (2024). patchwork: Composer Plots. R package version 1.2.0.9000, https://github.com/thomasp85/patchwork, https://patchwork.data-imaginist.com.","code":"@Manual{, title = {patchwork: The Composer of Plots}, author = {Thomas Lin Pedersen}, year = {2024}, note = {R package version 1.2.0.9000, https://github.com/thomasp85/patchwork}, url = {https://patchwork.data-imaginist.com}, }"},{"path":"https://patchwork.data-imaginist.com/index.html","id":"patchwork-","dir":"","previous_headings":"","what":"The Composer of Plots","title":"The Composer of Plots","text":"goal patchwork make ridiculously simple combine separate ggplots graphic. tries solve problem gridExtra::grid.arrange() cowplot::plot_grid using API incites exploration iteration, scales arbitrarily complex layouts.","code":""},{"path":"https://patchwork.data-imaginist.com/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"The Composer of Plots","text":"can install patchwork CRAN using install.packages('patchwork'). Alternatively can grab development version github using devtools:","code":"# install.packages(\"devtools\") devtools::install_github(\"thomasp85/patchwork\")"},{"path":"https://patchwork.data-imaginist.com/index.html","id":"basic-example","dir":"","previous_headings":"","what":"Basic example","title":"The Composer of Plots","text":"usage patchwork simple: just add plots together! patchwork provides rich support arbitrarily complex layouts full alignment. example, check readable code nesting three plots top third:","code":"library(ggplot2) library(patchwork) p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p1 + p2 p3 <- ggplot(mtcars) + geom_smooth(aes(disp, qsec)) p4 <- ggplot(mtcars) + geom_bar(aes(carb)) (p1 | p2 | p3) / p4"},{"path":"https://patchwork.data-imaginist.com/index.html","id":"learn-more","dir":"","previous_headings":"","what":"Learn more","title":"The Composer of Plots","text":"patchwork can much . Check guides learning everything know different features: Getting Started Assembling Plots Defining Layouts Adding Annotation Aligning across pages","code":""},{"path":"https://patchwork.data-imaginist.com/index.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"The Composer of Plots","text":"Please note patchwork project released Contributor Code Conduct. contributing project, agree abide terms.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/align_plots.html","id":null,"dir":"Reference","previous_headings":"","what":"Deprecated functions — align_plots","title":"Deprecated functions — align_plots","text":"functions deprecated used.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/area.html","id":null,"dir":"Reference","previous_headings":"","what":"Specify a plotting area in a layout — area","title":"Specify a plotting area in a layout — area","text":"small helper used specify single area rectangular grid contain plot. Objects constructed area() can concatenated together c() order specify multiple areas.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/area.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Specify a plotting area in a layout — area","text":"","code":"area(t, l, b = t, r = l)"},{"path":"https://patchwork.data-imaginist.com/reference/area.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Specify a plotting area in a layout — area","text":"t, b top bottom bounds area grid l, r left right bounds area int grid","code":""},{"path":"https://patchwork.data-imaginist.com/reference/area.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Specify a plotting area in a layout — area","text":"patch_area object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/area.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Specify a plotting area in a layout — area","text":"grid areas specified reference enumerate rows top bottom, coloumns left right. means t l always less equal b r respectively. Instead specifying area placement combination area() calls, possible instead pass single string equivalent example , see plot_layout() examples.","code":"areas <- c(area(1, 1, 2, 1), area(2, 3, 3, 3)) areas < -\"A## A#B ##B\""},{"path":"https://patchwork.data-imaginist.com/reference/area.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Specify a plotting area in a layout — area","text":"","code":"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)"},{"path":"https://patchwork.data-imaginist.com/reference/free.html","id":null,"dir":"Reference","previous_headings":"","what":"Free a plot from various alignments — free","title":"Free a plot from various alignments — free","text":"purpose patchwork often align plots various parts, sometimes cut want compose plots without alignment. free() function tells patchwork treat content (can either ggplot patchwork) specially align remaining plots composition. free() various modes control type \"non-alignment\" applied (see Details). can control side plot non-alignment applied . can stack free() calls e.g. want top part align panel left part align labels.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/free.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Free a plot from various alignments — free","text":"","code":"free(x, type = c(\"panel\", \"label\", \"space\"), side = \"trbl\")"},{"path":"https://patchwork.data-imaginist.com/reference/free.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Free a plot from various alignments — free","text":"x ggplot patchwork object type type freeing applied. See Details section side side freeing applied . string containing one \"t\", \"r\", \"b\", \"l\"","code":""},{"path":"https://patchwork.data-imaginist.com/reference/free.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Free a plot from various alignments — free","text":"modified version x free_plot class","code":""},{"path":"https://patchwork.data-imaginist.com/reference/free.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Free a plot from various alignments — free","text":"free() multiple modes depending needing: default \"panel\" allow panel area ignore alginment remaining plots expand much needed fill empty space. \"label\" type instead free axis label keep proximity axis, even longer axis text another plot push apart. \"space\" type also keeps axis title together, instead reserve space . allows axis occupy space otherwise empty area without making additional space available .","code":""},{"path":"https://patchwork.data-imaginist.com/reference/free.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Free a plot from various alignments — free","text":"","code":"# 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 (here, with the default \"panel\" type) free(p1) / p2 # If we still want the panels to be aligned to the right, we can choose to # free only the left side free(p1, side = \"l\") / p2 # We can still collect guides like before free(p1) / p2 + plot_layout(guides = \"collect\") # We could use \"label\" to fix the layout in a different way p1 / free(p2, \"label\") # Another issue is that long labels are not using already available free # space. plot_spacer() + p1 + p2 + p2 # This can be fixed with the \"space\" type plot_spacer() + free(p1, \"space\", \"l\") + p2 + p2"},{"path":"https://patchwork.data-imaginist.com/reference/guide_area.html","id":null,"dir":"Reference","previous_headings":"","what":"Add an area to hold collected guides — guide_area","title":"Add an area to hold collected guides — guide_area","text":"Using guides argument plot_layout() can collect collapse guides plots. default guides put side like regular plots, adding guide_area() plot can tell patchwork place guides area instead. guides collected guides exists collect behaves standard plot_spacer() instead.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/guide_area.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add an area to hold collected guides — guide_area","text":"","code":"guide_area()"},{"path":"https://patchwork.data-imaginist.com/reference/guide_area.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add an area to hold collected guides — guide_area","text":"","code":"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')"},{"path":"https://patchwork.data-imaginist.com/reference/inset_element.html","id":null,"dir":"Reference","previous_headings":"","what":"Create an inset to be added on top of the previous plot — inset_element","title":"Create an inset to be added on top of the previous plot — inset_element","text":"standard approach patchwork place plots next based provided layout. However, may sometimes beneficial place one several plots graphic elements freely top another plot. inset_element() function provides way create insets gives full control placement.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/inset_element.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create an inset to be added on top of the previous plot — inset_element","text":"","code":"inset_element( p, left, bottom, right, top, align_to = \"panel\", on_top = TRUE, clip = TRUE, ignore_tag = FALSE )"},{"path":"https://patchwork.data-imaginist.com/reference/inset_element.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create an inset to be added on top of the previous plot — inset_element","text":"p grob, ggplot, patchwork, formula, raster, nativeRaster, gt object add inset left, bottom, right, top numerics units giving location outer bounds. given numerics converted npc units. align_to Specifies left, bottom, etc relative . Either 'panel' (default), 'plot', 'full'. on_top Logical. inset placed top plot (background)? clip Logical. clipping performed inset? ignore_tag Logical. autotagging ignore inset?","code":""},{"path":"https://patchwork.data-imaginist.com/reference/inset_element.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create an inset to be added on top of the previous plot — inset_element","text":"inset_path object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/inset_element.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create an inset to be added on top of the previous plot — inset_element","text":"","code":"library(ggplot2) p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) # Basic use p1 + inset_element(p2, 0.6, 0.6, 1, 1) # Align to the full area instead p1 + inset_element(p2, 0, 0.6, 0.4, 1, align_to = 'full') # Grobs and other objects can be added as insets as well p1 + inset_element(grid::circleGrob(), 0.4, 0.4, 0.6, 0.6) if (requireNamespace('png', quietly = TRUE)) { logo <- system.file('help', 'figures', 'logo.png', package = 'patchwork') logo <- png::readPNG(logo, native = TRUE) p1 + inset_element(logo, 0.8, 0.8, 1, 1, align_to = 'full') } # Just as expected insets are still amenable to changes after the fact p1 + inset_element(p2, 0.6, 0.6, 1, 1) + theme_classic() # Tagging also continues to work as expected p1 + inset_element(p2, 0.6, 0.6, 1, 1) + plot_annotation(tag_levels = '1') # but can be turned off, like for wrapped plots p1 + inset_element(p2, 0.6, 0.6, 1, 1, ignore_tag = TRUE) + plot_annotation(tag_levels = '1')"},{"path":"https://patchwork.data-imaginist.com/reference/multipage_align.html","id":null,"dir":"Reference","previous_headings":"","what":"Align plots across multiple pages — multipage_align","title":"Align plots across multiple pages — multipage_align","text":"Sometimes necessary make sure separate plots aligned, , still exists separate plots. e.g. need part slideshow want titles panels jumping around switch slides. patchwork provides range utilities achieve . Currently possible align ggplots, aligning patchworks supported future.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/multipage_align.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Align plots across multiple pages — multipage_align","text":"","code":"get_dim(plot) set_dim(plot, dim) get_max_dim(...) align_patches(...)"},{"path":"https://patchwork.data-imaginist.com/reference/multipage_align.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Align plots across multiple pages — multipage_align","text":"plot ggplot object dim plot_dimension object created get_dim() ... ggplot objects single list ","code":""},{"path":"https://patchwork.data-imaginist.com/reference/multipage_align.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Align plots across multiple pages — multipage_align","text":"get_dim() get_max_dim() return plot_dimension object. set_dim() returns modified ggplot object fixed outer dimensions align_patches() return list . modified ggplots still behaves like standard ggplot new layers, scales, etc can added .","code":""},{"path":"https://patchwork.data-imaginist.com/reference/multipage_align.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Align plots across multiple pages — multipage_align","text":"","code":"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()"},{"path":"https://patchwork.data-imaginist.com/reference/patchGrob.html","id":null,"dir":"Reference","previous_headings":"","what":"Get a grob describing the content of a patch object — patchGrob","title":"Get a grob describing the content of a patch object — patchGrob","text":"Methods generic defined patch subclasses return compliant gtable object ready combined regular plot objects. general best call patch_table() object add grobs patch_table() return compliant gtable","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchGrob.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get a grob describing the content of a patch object — patchGrob","text":"","code":"patchGrob(x, guides = \"auto\")"},{"path":"https://patchwork.data-imaginist.com/reference/patchGrob.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get a grob describing the content of a patch object — patchGrob","text":"x patch object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchGrob.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get a grob describing the content of a patch object — patchGrob","text":"gtable object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchwork-package.html","id":null,"dir":"Reference","previous_headings":"","what":"patchwork: The Composer of Plots — patchwork-package","title":"patchwork: The Composer of Plots — patchwork-package","text":"'ggplot2' package provides strong API sequentially building plot, concern composition multiple plots. 'patchwork' package expands API allow arbitrarily complex composition plots , among others, providing mathematical operators combining multiple plots. packages try address need (different approach) 'gridExtra' 'cowplot'.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchwork-package.html","id":"overview","dir":"Reference","previous_headings":"","what":"Overview","title":"patchwork: The Composer of Plots — patchwork-package","text":"use premise patchwork simple: Just add ggplot2 plots together compose multiplot layouts. simplicity much say. Still, functions allow modify behaviour, e.g.: plot_layout() allows define grid plots put plot_annotation() allows add titles, tags etc.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchwork-package.html","id":"learn-more","dir":"Reference","previous_headings":"","what":"Learn more","title":"patchwork: The Composer of Plots — patchwork-package","text":"guides teach can patchwork. Getting Started Assembling Plots Defining Layouts Adding Annotation Aligning across pages","code":""},{"path":[]},{"path":"https://patchwork.data-imaginist.com/reference/patchwork-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"patchwork: The Composer of Plots — patchwork-package","text":"Maintainer: Thomas Lin Pedersen thomasp85@gmail.com (ORCID)","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchwork-package.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"patchwork: The Composer of Plots — patchwork-package","text":"","code":"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))"},{"path":"https://patchwork.data-imaginist.com/reference/patchworkGrob.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert a patchwork to a gtable — patchworkGrob","title":"Convert a patchwork to a gtable — patchworkGrob","text":"function patchwork analogue ggplot2::ggplotGrob() takes unevaluated patchwork object fixate gtable object manipulate directly.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchworkGrob.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert a patchwork to a gtable — patchworkGrob","text":"","code":"patchworkGrob(x)"},{"path":"https://patchwork.data-imaginist.com/reference/patchworkGrob.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert a patchwork to a gtable — patchworkGrob","text":"x patchwork object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchworkGrob.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert a patchwork to a gtable — patchworkGrob","text":"gtable object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_annotation.html","id":null,"dir":"Reference","previous_headings":"","what":"Annotate the final patchwork — plot_annotation","title":"Annotate the final patchwork — plot_annotation","text":"result function can added patchwork using + way plot_layout(), unlike plot_layout() effect top level plot. name suggests controls different aspects annotation final plot, titles tags. Already added annotations can removed setting relevant argument NULL.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_annotation.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Annotate the final patchwork — plot_annotation","text":"","code":"plot_annotation( title = waiver(), subtitle = waiver(), caption = waiver(), tag_levels = waiver(), tag_prefix = waiver(), tag_suffix = waiver(), tag_sep = waiver(), theme = waiver() )"},{"path":"https://patchwork.data-imaginist.com/reference/plot_annotation.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Annotate the final patchwork — plot_annotation","text":"title, subtitle, caption Text strings use various plot annotations. tag_levels character vector defining enumeration format use level. Possible values '' lowercase letters, '' uppercase letters, '1' numbers, '' lowercase Roman numerals, '' uppercase Roman numerals. can also list containing character vectors defining arbitrary tag sequences. element list scalar one '', '', '1', ', '', level expanded expected sequence. tag_prefix, tag_suffix Strings appear tag. tag_sep separator different tag levels theme ggplot theme specification use plot. elements related titles well plot margin background used.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_annotation.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Annotate the final patchwork — plot_annotation","text":"plot_annotation object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_annotation.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Annotate the final patchwork — plot_annotation","text":"Tagging subplots done automatically following order plots added. plot contains nested layouts tag_level argument nested plot_layout define whether enumeration continue usual add new level. format levels defined tag_levels argument plot_annotation","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_annotation.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Annotate the final patchwork — plot_annotation","text":"","code":"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) # Add title, etc. to a patchwork p1 + p2 + plot_annotation('This is a title', caption = 'made with patchwork') # Change styling of patchwork elements p1 + p2 + plot_annotation( title = 'This is a title', caption = 'made with patchwork', theme = theme(plot.title = element_text(size = 16)) ) # Add tags to plots p1 / (p2 | p3) + plot_annotation(tag_levels = 'A') # Add multilevel tagging to nested layouts p1 / ((p2 | p3) + plot_layout(tag_level = 'new')) + plot_annotation(tag_levels = c('A', '1')) # Use a custom tag sequence (mixed with a standard one) p1 / ((p2 | p3) + plot_layout(tag_level = 'new')) + plot_annotation(tag_levels = list(c('&', '%'), '1'))"},{"path":"https://patchwork.data-imaginist.com/reference/plot_arithmetic.html","id":null,"dir":"Reference","previous_headings":"","what":"Plot arithmetic — plot_arithmetic","title":"Plot arithmetic — plot_arithmetic","text":"addition + operator known ggplot2, patchwork defines logic operators aids building plot composition reduce code-reuse.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_arithmetic.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Plot arithmetic — plot_arithmetic","text":"","code":"# S3 method for class 'ggplot' e1 - e2 # S3 method for class 'ggplot' e1/e2 # S3 method for class 'ggplot' e1 | e2 # S3 method for class 'gg' e1 * e2 # S3 method for class 'gg' e1 & e2"},{"path":"https://patchwork.data-imaginist.com/reference/plot_arithmetic.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Plot arithmetic — plot_arithmetic","text":"e1 ggplot patchwork object e2 ggplot patchwork object case /, gg object geom theme specification case * &","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_arithmetic.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Plot arithmetic — plot_arithmetic","text":"patchwork object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_arithmetic.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Plot arithmetic — plot_arithmetic","text":"patchwork augment + operator ggplot2 allows user add full ggplot objects together order compose view. last added plot always active one new geoms etc. added . Another operator much like , quite, -. also adds plots together instead adding right hand side patchwork defined left hand side, puts left hand side besides right hand side patchwork. might sound confusing, essence - ensures right left side put nesting level (+ puts right side left side). Using - might seem unintuitive think operator \"subtract\", look hyphen instead (underlying reason - operator precedence group +). alternative explicit way get effect - use merge() left hand side. Often interested creating single column single row layouts. patchwork provides | (besides) / () operators support stacking packing plots. See examples use. order reduce code repetition patchwork provides two operators adding ggplot elements (geoms, themes, facets, etc.) multiple/plots patchwork. * add element plots current nesting level, & recurse nested patches.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_arithmetic.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Plot arithmetic — plot_arithmetic","text":"","code":"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)) # Standard addition vs division p1 + p2 + p3 + plot_layout(ncol = 1) p1 + p2 - p3 + plot_layout(ncol = 1) # Stacking and packing (p1 | p2 | p3) / p4 # Add elements to the same nesting level (p1 + (p2 + p3) + p4 + plot_layout(ncol = 1)) * theme_bw() # Recurse into nested plots as well (p1 + (p2 + p3) + p4 + plot_layout(ncol = 1)) & theme_bw()"},{"path":"https://patchwork.data-imaginist.com/reference/plot_layout.html","id":null,"dir":"Reference","previous_headings":"","what":"Define the grid to compose plots in — plot_layout","title":"Define the grid to compose plots in — plot_layout","text":"control different plots laid , need add layout specification. nesting grids, layout scoped current nesting level. already set value can removed setting NULL.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_layout.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Define the grid to compose plots in — plot_layout","text":"","code":"plot_layout( ncol = waiver(), nrow = waiver(), byrow = waiver(), widths = waiver(), heights = waiver(), guides = waiver(), tag_level = waiver(), design = waiver(), axes = waiver(), axis_titles = axes )"},{"path":"https://patchwork.data-imaginist.com/reference/plot_layout.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Define the grid to compose plots in — plot_layout","text":"ncol, nrow dimensions grid create - NULL use logic facet_wrap() set dimensions byrow Analogous byrow matrix(). FALSE plots filled column-major order widths, heights relative widths heights column row grid. get repeated match dimensions grid. special value NA/-1null behave 1null unless fixed aspect plot inserted case allow dimension expand contract match aspect ratio content guides string specifying guides treated layout. 'collect' collect guides given nesting level, removing duplicates. 'keep' stop collection level let guides placed alongside plot. auto allow guides collected upper level tries, place alongside plot . modify default guide \"position\" theme(legend.position=...) also collecting guides must apply change overall patchwork (see example). tag_level string ('keep' 'new') indicate auto-tagging behave. See plot_annotation(). design Specification location areas layout. Can either specified text string concatenating calls area() together. See examples information use. axes string specifying axes treated. 'keep' retain axes individual plots. 'collect' remove duplicated axes placed run rows columns layout. 'collect_x' 'collect_y' remove duplicated x-axes columns duplicated y-axes rows respectively. axis_titles string specifying axis titltes treated. 'keep' retain axis titles individual plots. 'collect' remove duplicated titles one direction merge titles opposite direction. 'collect_x' 'collect_y' control x-axis titles y-axis titles respectively.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_layout.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Define the grid to compose plots in — plot_layout","text":"plot_layout object added ggassmble object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_layout.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Define the grid to compose plots in — plot_layout","text":"","code":"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')"},{"path":"https://patchwork.data-imaginist.com/reference/plot_spacer.html","id":null,"dir":"Reference","previous_headings":"","what":"Add a completely blank area — plot_spacer","title":"Add a completely blank area — plot_spacer","text":"simple wrapper creates empty transparent patch can added push plots apart. patch responds adding theme() specifications, plot.background effect.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_spacer.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add a completely blank area — plot_spacer","text":"","code":"plot_spacer()"},{"path":"https://patchwork.data-imaginist.com/reference/plot_spacer.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add a completely blank area — plot_spacer","text":"ggplot object containing empty plot","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_spacer.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add a completely blank area — plot_spacer","text":"","code":"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\")))"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_elements.html","id":null,"dir":"Reference","previous_headings":"","what":"Wrap arbitrary graphics in a patchwork-compliant patch — wrap_elements","title":"Wrap arbitrary graphics in a patchwork-compliant patch — wrap_elements","text":"order add non-ggplot2 element patchwork can converted compliant representation using wrap_elements() function. allows position either grobs, ggplot objects, patchwork objects, even base graphics (passed formula) either full area, full plotting area (anything including axis label), panel area (actual area data drawn). can still add title, subtitle, tag, caption using approach normal ggplots (using ggtitle() labs()) well styling using theme(). latter, theme elements targeting plot margins background well title, subtitle, etc styling effect. patchwork ggplot object wrapped, fixated state longer respond addition styling, geoms, etc.. grobs formulas added directly, implicitly converted wrap_elements(full = x).","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_elements.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Wrap arbitrary graphics in a patchwork-compliant patch — wrap_elements","text":"","code":"wrap_elements( panel = NULL, plot = NULL, full = NULL, clip = TRUE, ignore_tag = FALSE )"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_elements.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Wrap arbitrary graphics in a patchwork-compliant patch — wrap_elements","text":"panel, plot, full grob, ggplot, patchwork, formula, raster, nativeRaster, gt object add respective area. clip grobs clipped expanding outside area ignore_tag tags ignored patch. relevant using automatic tagging plots content patch qualify tag.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_elements.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Wrap arbitrary graphics in a patchwork-compliant patch — wrap_elements","text":"wrapped_patch object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_elements.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Wrap arbitrary graphics in a patchwork-compliant patch — wrap_elements","text":"","code":"library(ggplot2) library(grid) # Combine grobs with each other wrap_elements(panel = textGrob('Here are some text')) + wrap_elements( panel = rectGrob(gp = gpar(fill = 'steelblue')), full = rectGrob(gp = gpar(fill = 'goldenrod')) ) # wrapped elements can still get titles etc like ggplots wrap_elements(panel = textGrob('Here are some text')) + wrap_elements( panel = rectGrob(gp = gpar(fill = 'steelblue')), full = rectGrob(gp = gpar(fill = 'goldenrod')) ) + ggtitle('Title for the amazing rectangles') # You can also pass in ggplots or patchworks to e.g. have it fill out the # panel area p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p1 + wrap_elements(panel = p1 + ggtitle('Look at me shrink')) # You can even add base graphics if you pass it as a formula (requires gridGraphics package) if (requireNamespace(\"gridGraphics\", quietly = TRUE)) { p1 + wrap_elements(full = ~ plot(mtcars$mpg, mtcars$disp)) # Adding a grob or formula directly is equivalent to placing it in `full` p1 + ~ plot(mtcars$mpg, mtcars$disp) }"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_ggplot_grob.html","id":null,"dir":"Reference","previous_headings":"","what":"Make a gtable created from a ggplot object patchwork compliant — wrap_ggplot_grob","title":"Make a gtable created from a ggplot object patchwork compliant — wrap_ggplot_grob","text":"function converts gtable, produced ggplot2::ggplotGrob() makes ready added patchwork. contrast passing gtable wrap_elements(), wrap_ggplot_grob() ensures proper alignment expected. hand major restructuring gtable result object work properly wrap_ggplot_grob().","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_ggplot_grob.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Make a gtable created from a ggplot object patchwork compliant — wrap_ggplot_grob","text":"","code":"wrap_ggplot_grob(x)"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_ggplot_grob.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Make a gtable created from a ggplot object patchwork compliant — wrap_ggplot_grob","text":"x gtable produced ggplot2::ggplotGrob()","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_ggplot_grob.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Make a gtable created from a ggplot object patchwork compliant — wrap_ggplot_grob","text":"table_patch object added patchwork","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_ggplot_grob.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Make a gtable created from a ggplot object patchwork compliant — wrap_ggplot_grob","text":"","code":"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)"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_plots.html","id":null,"dir":"Reference","previous_headings":"","what":"Wrap plots into a patchwork — wrap_plots","title":"Wrap plots into a patchwork — wrap_plots","text":"use + natural way add plots together, can difficult string together multiple plots programmatically number plots known beforehand. wrap_plots makes easy take list plots add one composition, along layout specifications.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_plots.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Wrap plots into a patchwork — wrap_plots","text":"","code":"wrap_plots( ..., ncol = NULL, nrow = NULL, byrow = NULL, widths = NULL, heights = NULL, guides = NULL, tag_level = NULL, design = NULL, axes = NULL, axis_titles = axes )"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_plots.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Wrap plots into a patchwork — wrap_plots","text":"... multiple ggplots list containing ggplot objects ncol, nrow dimensions grid create - NULL use logic facet_wrap() set dimensions byrow Analogous byrow matrix(). FALSE plots filled column-major order widths, heights relative widths heights column row grid. get repeated match dimensions grid. special value NA/-1null behave 1null unless fixed aspect plot inserted case allow dimension expand contract match aspect ratio content guides string specifying guides treated layout. 'collect' collect guides given nesting level, removing duplicates. 'keep' stop collection level let guides placed alongside plot. auto allow guides collected upper level tries, place alongside plot . modify default guide \"position\" theme(legend.position=...) also collecting guides must apply change overall patchwork (see example). tag_level string ('keep' 'new') indicate auto-tagging behave. See plot_annotation(). design Specification location areas layout. Can either specified text string concatenating calls area() together. See examples information use. axes string specifying axes treated. 'keep' retain axes individual plots. 'collect' remove duplicated axes placed run rows columns layout. 'collect_x' 'collect_y' remove duplicated x-axes columns duplicated y-axes rows respectively. axis_titles string specifying axis titltes treated. 'keep' retain axis titles individual plots. 'collect' remove duplicated titles one direction merge titles opposite direction. 'collect_x' 'collect_y' control x-axis titles y-axis titles respectively.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_plots.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Wrap plots into a patchwork — wrap_plots","text":"patchwork object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_plots.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Wrap plots into a patchwork — wrap_plots","text":"design specified text string plots named (e.g. wrap_plots(= p1, ...)) plot names single characters represented design layout string, plots matched respective area name. Otherwise areas filled sequentially manner using + operator. See examples .","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_plots.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Wrap plots into a patchwork — wrap_plots","text":"","code":"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)) # Either add the plots as single arguments wrap_plots(p1, p2, p3, p4, p5) # Or add them as a list... plots <- list(p1, p2, p3, p4, p5) wrap_plots(plots) # Match plots to areas by name design <- \"#BB AA#\" wrap_plots(B = p1, A = p2, design = design) # Compare to not using named plot arguments wrap_plots(p1, p2, design = design)"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_table.html","id":null,"dir":"Reference","previous_headings":"","what":"Wrap a table in a patchwork compliant patch — wrap_table","title":"Wrap a table in a patchwork compliant patch — wrap_table","text":"function works much like wrap_elements() turns input patchwork compliant objects can added composition. However, wrap_table() uses knowledge input table provide nifty layout options makes generally better use wrap_elements() type object.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_table.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Wrap a table in a patchwork compliant patch — wrap_table","text":"","code":"wrap_table( table, panel = c(\"body\", \"full\", \"rows\", \"cols\"), space = c(\"free\", \"free_x\", \"free_y\", \"fixed\"), ignore_tag = FALSE )"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_table.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Wrap a table in a patchwork compliant patch — wrap_table","text":"table gt table object coercible data frame panel portion table aligned panel region? \"body\" means column row headers placed outside panel region, .e. topleft corner panel region aligned topleft data cell. \"full\" means whole table placed inside panel region. \"rows\" means rows (including column headers) placed inside panel region row headers placed left. \"cols\" opposite, placing columns within panel region keeping column header top . set \"body\" \"cols\" space set \"fixed\" \"free_x\" footnotes source notes table placed outside bottom panel region. space dimension table influence final composition? \"fixed\" means table width set width column occupies table height set height row occupies. \"free\" opposite meaning table dimension influence sizing. \"free_x\" \"free_y\" allows free either direction keeping remaining fixed. note set specific width height plot_layout() higher priority table dimensions ignore_tag tags ignored patch. relevant using automatic tagging plots content patch qualify tag.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_table.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Wrap a table in a patchwork compliant patch — wrap_table","text":"wrapped_table object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_table.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Wrap a table in a patchwork compliant patch — wrap_table","text":"functionality requires v0.11.0 higher gt package","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_table.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Wrap a table in a patchwork compliant patch — wrap_table","text":"","code":"library(ggplot2) library(gt) p1 <- ggplot(airquality) + geom_line(aes(x = Day, y = Temp, colour = month.name[Month])) + labs(colour = \"Month\") table <- data.frame( Month = month.name[5:9], \"Mean temp.\" = tapply(airquality$Temp, airquality$Month, mean), \"Min temp.\" = tapply(airquality$Temp, airquality$Month, min), \"Max temp.\" = tapply(airquality$Temp, airquality$Month, max) ) gt_tab <- gt(table, rowname_col = \"Month\") # Default addition usees wrap_table p1 + gt_tab # Default places column and row headers outside panel area. Use wrap_table # to control this p1 + wrap_table(gt_tab, panel = \"full\") # Tables generally have fixed dimensions and these can be used to control # the size of the area they occupy p2 <- ggplot(airquality) + geom_boxplot(aes(y = month.name[Month], x = Temp)) + scale_y_discrete(name = NULL, limits = month.name[9:5], guide = \"none\") wrap_table(gt_tab, space = \"fixed\") + p2"},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-development-version","dir":"Changelog","previous_headings":"","what":"patchwork (development version)","title":"patchwork (development version)","text":"free() now better aligns plots horizontal direction Plot backgrounds now always placed beneath elements patchwork (#370) Axis titles can now reliably collected even faceted plots (#367) Native support gt objects, either adding directly controlling layout wrap_table() Empty patches longer breaks axis title collection (#375) wrap_ggplot_grob() now respects auto-tagging (#363) Fix bug guide collecting prevent proper axes collecting (#359) Fix bug free() tags placed top plot region become missing (#350) free() gains type side argument. first control whether free panel, label, space occupied outside panel, second control sides applies (#345 #379) .list() now provided patchwork objects get plots patchwork list. also allows use lapply() friends patchwork objects (#381) default arguments plot_annotation() plot_layout() now waiver() allowing use NULL remove already set value (#198) Guide axis merging slightly robust comes merging different graphical parameters means used (e.g. “black” “#000000”) (#369) fix bug collecting guides null unit key size (#390) Added nest() explicitly nest patchwork LHS operator","code":""},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-120","dir":"Changelog","previous_headings":"","what":"patchwork 1.2.0","title":"patchwork 1.2.0","text":"CRAN release: 2024-01-08 Axes axis titles can now collected using plot_layout() function. Collecting axes remove duplicated axes x- y-direction. Collecting axis titles also remove duplicated titles x- y-direction, also merge duplicated titles direction (#150). Fix bug prevented faceted plots axes right used (#340) Added free() function mark plot aligned rest. margin plot still aligned margins plots everything inside unaligned.","code":""},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-113","dir":"Changelog","previous_headings":"","what":"patchwork 1.1.3","title":"patchwork 1.1.3","text":"CRAN release: 2023-08-14 NULL can now used different arithmetic operators result non-operation (.e. non-null part returned unmodified) (#290) Fix bug prevented plots multi-level strips merged together (#277) Patchworks now render correctly unserialised fresh session, providing patchwork package available (#242) Fixed bug preventing faceted plots strip placement outside axis aligned (#325) Fixed bug let inconsistent results combining fixed aspect plots different order (#274) Fixed bug prevented nested patchworks empty columns rows bottom right inserted layout (#273) Patchwork objects now behaves correctly like unnamed list ggplots. makes View() work (#317), allow one use length() determine number patches patchwork (#293) Expressions calls can now used plot annotations way can used titles ggplot2 (#295)","code":""},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-112","dir":"Changelog","previous_headings":"","what":"patchwork 1.1.2","title":"patchwork 1.1.2","text":"CRAN release: 2022-08-19 Better error message rendering fails due small plotting space","code":""},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-111","dir":"Changelog","previous_headings":"","what":"patchwork 1.1.1","title":"patchwork 1.1.1","text":"CRAN release: 2020-12-17 Use vdiffr conditionally pass test M1 mac Add str() method patchwork objects (#217) Fix bug inset_element() insetting plots fixed dimensions (#214) Make sure -, /, | works supported object types (#221)","code":""},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-110","dir":"Changelog","previous_headings":"","what":"patchwork 1.1.0","title":"patchwork 1.1.0","text":"CRAN release: 2020-11-09 Add inset_element() allow adding plots insets patchwork now supports raster nativeRaster objects Avoid incrementing tag counter recursing nested plot without additional tags use (#147) Fix bug prevented strips turned element_blank() working (#200) Add option supply custom sequence tags use auto-tagging (#211, #63)","code":""},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-101","dir":"Changelog","previous_headings":"","what":"patchwork 1.0.1","title":"patchwork 1.0.1","text":"CRAN release: 2020-06-22 Renaming align_plots() align_patches() avoid namespace clash cowplot (#130) Renaming as_grob() (unexported) as_patch() avoid potential future namespace clash cowplot (#131) Fix bug plot simplification theme(strip.placement = 'outside') (#132) Fix bug guide collection R >= 4.0 due new unit implementation grid (#170) Collected guides now behave ggplot2 guides position top bottom (#137) Fix bug base graphic support environment plot captured (#138) Fix bug combining plots guides placed manually combination faceting (#144) Fix bug negative margins around legend result unintelligeble error (#148) Fix bug trying combine faceted plots fixed aspect ratio (#156) Fix alignments strips single strip present (#163) Fix bug caused theme void result errors (#180) Make aligning multiple fixed aspect plots consistent (#175)","code":""},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-100","dir":"Changelog","previous_headings":"","what":"patchwork 1.0.0","title":"patchwork 1.0.0","text":"CRAN release: 2019-12-01 First CRAN release. Provide utility operators assembling nesting plots composition, tag subplots, collect guides remove duplicates, align plots across pages.","code":""}] +[{"path":"https://patchwork.data-imaginist.com/CODE_OF_CONDUCT.html","id":null,"dir":"","previous_headings":"","what":"Contributor Code of Conduct","title":"Contributor Code of Conduct","text":"contributors maintainers project, pledge respect people contribute reporting issues, posting feature requests, updating documentation, submitting pull requests patches, activities. committed making participation project harassment-free experience everyone, regardless level experience, gender, gender identity expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion. Examples unacceptable behavior participants include use sexual language imagery, derogatory comments personal attacks, trolling, public private harassment, insults, unprofessional conduct. Project maintainers right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct. Project maintainers follow Code Conduct may removed project team. Instances abusive, harassing, otherwise unacceptable behavior may reported opening issue contacting one project maintainers. Code Conduct adapted Contributor Covenant (https://www.contributor-covenant.org), version 1.0.0, available https://contributor-covenant.org/version/1/0/0/.","code":""},{"path":"https://patchwork.data-imaginist.com/articles/guides/annotation.html","id":"titles-subtitles-and-captions","dir":"Articles > Guides","previous_headings":"","what":"Titles, subtitles and captions","title":"Adding Annotation and Style","text":"One needed things add descriptive text plot ensemble. achieve , simply add patchwork using plot_annotation() important note plot annotations effect top-level patchwork. annotation added nested patchworks (currently) lost. need annotations nested patchwork ’ll need wrap wrap_elements() side-effect alignment longer works.","code":"patchwork <- (p1 + p2) / p3 patchwork + plot_annotation( title = 'The surprising truth about mtcars', subtitle = 'These 3 plots will reveal yet-untold secrets about our beloved data-set', caption = 'Disclaimer: None of these plots are insightful' )"},{"path":"https://patchwork.data-imaginist.com/articles/guides/annotation.html","id":"tagging","dir":"Articles > Guides","previous_headings":"","what":"Tagging","title":"Adding Annotation and Style","text":"Often, especially scientific literature, multiple plots collected single figure referred tag. tags added manually, much simpler let patchwork handle , using auto-tagging functionality. turned setting tag_level plot_annotation() value indicating family symbols use tagging: '1' Arabic numerals, '' uppercase Latin letters, '' lowercase Latin letters, '' uppercase Roman numerals, '' lowercase Roman numerals. Tags uses theming plot applied , make sure match , modify theming plots using & (see Plot Assembly guide). patchwork contains nested layouts tagging recurse default, can tell define new tagging level tag_level argument plot_layout(). can provide multiple tag-types tag_levels define subtagging enumerated. plot_annotation()also possible define separator, prefix, suffix tag, don’t go overboard : default ggplot2 theme puts tag row column expand fit. longer tag text look weird, better place top plot region: Lastly also possible provide tag sequence instead relying build ones. Passing list character vectors just (note can mixed standard sequences): provide plots custom sequence support excess plots get empty tags make sure ’s enough.","code":"patchwork + plot_annotation(tag_levels = 'A') patchwork + plot_annotation(tag_levels = 'A') & theme(plot.tag = element_text(size = 8)) patchwork[[1]] <- patchwork[[1]] + plot_layout(tag_level = 'new') patchwork + plot_annotation(tag_levels = c('A', '1')) patchwork + plot_annotation(tag_levels = c('A', '1'), tag_prefix = 'Fig. ', tag_sep = '.', tag_suffix = ':') patchwork + plot_annotation(tag_levels = c('A', '1'), tag_prefix = 'Fig. ', tag_sep = '.', tag_suffix = ':') & theme(plot.tag.position = c(0, 1), plot.tag = element_text(size = 8, hjust = 0, vjust = 0)) patchwork + plot_annotation(tag_levels = list(c('#', '&'), '1'))"},{"path":"https://patchwork.data-imaginist.com/articles/guides/annotation.html","id":"styling-the-patchwork","dir":"Articles > Guides","previous_headings":"","what":"Styling the patchwork","title":"Adding Annotation and Style","text":"style patchwork made themes individual patches. coherent look, don’t mix widely different looks. Setting background colour single plot different shade effective way highlight , e.g. different fonts line widths just look like mess. patchwork elements susceptible theming: background, margin, title, subtitle & caption. theme patchwork default default ggplot2 theme. can changed though, two different ways. easiest simply use & theme element. operator add theme subplots well theme patchwork : need address theme patchwork (e.g. making patchwork title larger plot titles), can done theme argument plot_annotation() (note use one exclude ):","code":"patchwork + plot_annotation(title = 'The surprising truth about mtcars') & theme(text = element_text('mono')) patchwork + plot_annotation(title = 'The surprising truth about mtcars', theme = theme(plot.title = element_text(size = 18))) & theme(text = element_text('mono'))"},{"path":"https://patchwork.data-imaginist.com/articles/guides/annotation.html","id":"want-more","dir":"Articles > Guides","previous_headings":"","what":"Want more?","title":"Adding Annotation and Style","text":"Now know annotate style patchwork. Read guides assembling laying patchwork master patchwork.","code":""},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"adding-plots-to-the-patchwork","dir":"Articles > Guides","previous_headings":"","what":"Adding plots to the patchwork","title":"Plot Assembly","text":"point, shouldn’t come surprise can use + add plots together form patchwork. , ’d suggest start Getting Started guide, come back ’ve gone . , just recap: can add plots together, like : Using approach, possible assemble number plots, thing can added. patchworks can added, create new nested patchwork:","code":"p1 + p2 patch <- p1 + p2 p3 + patch"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"adding-tables","dir":"Articles > Guides","previous_headings":"Adding plots to the patchwork","what":"Adding tables","title":"Plot Assembly","text":"patchwork deep support working tables powered gt package provides means define align panel region well whether respect table size setting size rows columns patchwork. just want standard settings can add gt table directly plot want change settings wrap wrap_table() function. force table headers inside panel region sets sizing space table occupies based actual size table (note, using wrap_table() can pass data.frame directly)","code":"p1 + gt::gt(mtcars[1:10, c('mpg', 'disp')]) p1 + wrap_table(mtcars[1:10, c('mpg', 'disp')], panel = \"full\", space = \"fixed\")"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"adding-other-content","dir":"Articles > Guides","previous_headings":"Adding plots to the patchwork","what":"Adding other content","title":"Plot Assembly","text":"Sometimes need content ggplot2 patchwork. Standard grid grobs can added plot well: packages might provide even elaborate grob specifications can likewise added directly. Now , necessary work plots graphics package (base graphics). can added patchwork providing one-sided formula: Notice standard alignment ’d expect adding ggplots together longer works. general, way get consistent alignment ggplots base graphics, experiment different par() settings get something works particular use-case. ggplotify package provides even functionality converting different graphics grobs standard formula interface patchwork doesn’t work , check . workhorse underneath ability add non-ggplot objects patchwork wrap_elements() called implicitly adding non-ggplot objects. get bit control object added, wrap object directly wrap_elements(). can define object aligned full area, plot area. Combining setting margins zero clipping grob, can almost get perfect alignment: interesting side effect setup possible add labels styling wrapped element (though theme settings ignored). can come pretty close aligned base plot, always bit fiddly ad hoc. general simply recommended use ggplot2 possible. Another use case wrap_elements() need first plot ggplot. Patchwork able change + behavior miscellaneous objects, , appear first element must wrapped object patchwork understands:","code":"p1 + grid::textGrob('Some really important text') p1 + ~plot(mtcars$mpg, mtcars$disp, main = 'Plot 2') old_par <- par(mar = c(0, 2, 0, 0), bg = NA) p1 + wrap_elements(panel = ~plot(mtcars$mpg, mtcars$disp), clip = FALSE) par(old_par) old_par <- par(mar = c(0, 0, 0, 0), mgp = c(1, 0.25, 0), bg = NA, cex.axis = 0.75, las = 1, tcl = -0.25) p1 + wrap_elements(panel = ~plot(mtcars$mpg, mtcars$disp), clip = FALSE) + ggtitle('Plot 2') + theme(plot.margin = margin(5.5, 5.5, 5.5, 35)) par(old_par) # This won't do anything grid::textGrob('Text on left side') + p1 #> NULL # This will work wrap_elements(grid::textGrob('Text on left side')) + p1"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"stacking-and-packing","dir":"Articles > Guides","previous_headings":"Adding plots to the patchwork","what":"Stacking and packing","title":"Plot Assembly","text":"+ operator simply combines plots without telling patchwork anything desired layout. layout, unless changed plot_layout() (See Controlling Layout guide), simply grid enough rows columns contain number plots, square possible. special case putting plots besides top patchwork provides 2 shortcut operators. | place plots next / place top . 3 plots | behave just + using | communicate intend layout better. aware mixing operators put control operator precedence rule (e.g. / evaluated +). always good idea put sub-assemblies within braces avoid surprises:","code":"p1 / p2 p1 | p2 p1 / (p2 | p3)"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"functional-assembly","dir":"Articles > Guides","previous_headings":"Adding plots to the patchwork","what":"Functional assembly","title":"Plot Assembly","text":"using different operators provides clean API assembly, less suited situations control plot-generation process. handed list plot objects want assemble patchwork bit clumsy using + operator (doable loop Reduce()). patchwork provides wrap_plots() functional approach assembly. takes either separate plots list adds single patchwork. top also accepts arguments plot_layout() (see Controlling Layouts guide) can used single solution assembly needs:","code":"wrap_plots(p1, p2, p3, p4)"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"nesting-the-left-hand-side","dir":"Articles > Guides","previous_headings":"","what":"Nesting the left-hand side","title":"Plot Assembly","text":"plots always added patchwork left-hand side, possible nest left-hand side beside right-hand side standard operators shown . can lead surprising behavior: nest right-hand side, true left-hand side behavior necessary allow patchworks build gradually, get way left-hand side nested. patchwork provides - operator exact situation. conceptually understood hyphen minus, keeps side (puts nesting level): alternative - use merge() left hand side thing. Using approach possible use combination / | option using -. Yet another way solve wrap_plots(), put input nesting level, irrespective order:","code":"patch <- p1 + p2 p3 + patch patch + p3 patch - p3 wrap_plots(patch, p3)"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"modifying-patches","dir":"Articles > Guides","previous_headings":"","what":"Modifying patches","title":"Plot Assembly","text":"creating patchwork, resulting object remain ggplot object referencing last added plot. means can continue add objects geoms, scales, etc. normal ggplot: need modify another patch patchwork can access /modify double-bracket indexing. useful work function returns patchwork want modify one subplots:","code":"p1 + p2 + geom_jitter(aes(gear, disp)) patchwork <- p1 + p2 patchwork[[1]] <- patchwork[[1]] + theme_minimal() patchwork"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"modifying-everything","dir":"Articles > Guides","previous_headings":"Modifying patches","what":"Modifying everything","title":"Plot Assembly","text":"Often, especially comes theming, want modify everything . patchwork provides two additional operators facilitates . & add element subplots patchwork, * add element subplots current nesting level. | /, aware operator precedence must kept mind.","code":"patchwork <- p3 / (p1 | p2) patchwork & theme_minimal() patchwork * theme_minimal()"},{"path":"https://patchwork.data-imaginist.com/articles/guides/assembly.html","id":"want-more","dir":"Articles > Guides","previous_headings":"","what":"Want more?","title":"Plot Assembly","text":"everything know combining modifying patches patchwork. sure check guides controlling layouts annotations.","code":""},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"adding-an-empty-area","dir":"Articles > Guides","previous_headings":"","what":"Adding an empty area","title":"Controlling Layouts","text":"Sometimes needed empty area plots. can done adding plot_spacer(). occupy grid cell way plot without outer elements (titles, ticks, strips, etc.): important understand added area corresponds size plot panel. means spacers separate nesting levels may different dimensions:","code":"p1 + plot_spacer() + p2 + plot_spacer() + p3 + plot_spacer() (p1 + plot_spacer() + p2) / (plot_spacer() + p3 + plot_spacer())"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"controlling-the-grid","dir":"Articles > Guides","previous_headings":"","what":"Controlling the grid","title":"Controlling Layouts","text":"nothing given, patchwork try make grid square possible, erring side horizontal grid square possible (uses heuristic facet_wrap() ggplot2). , column row grid take space. can controlled plot_layout() grid sizes given numeric, define relative sizing panels. , panel area first column twice second column. also possible supply unit vector instead: last example first row always occupy 5cm, second expand fill remaining area. important remember sizing affects plotting region (panel area). plot , e.g., wide y-axis text penalized get smaller overall plotting region.","code":"p1 + p2 + p3 + p4 + plot_layout(ncol = 3) p1 + p2 + p3 + p4 + plot_layout(widths = c(2, 1)) p1 + p2 + p3 + p4 + plot_layout(widths = c(2, 1), heights = unit(c(5, 1), c('cm', 'null')))"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"moving-beyond-the-grid","dir":"Articles > Guides","previous_headings":"","what":"Moving beyond the grid","title":"Controlling Layouts","text":"Earlier, ’ve wanted create non-grid compositions, ’ve used nesting. often enough, end losing alignment subplots different nested areas. alternative define layout design fill plots . design can defined two different ways. easiest use textual representation: using textual representation responsibility make sure area rectangular. exception # denotes empty areas can thus shape. programmatic approach build layout using area() constructor. bit verbose easier program . , allows overlay plots. design specification can course also used widths heights specify size columns rows design. small additional feature design argument exists used conjunction wrap_plots() function (See Plot Assembly guide). design given textual representation, can name plots match different areas, instead letting filled order appear:","code":"layout <- \" ##BBBB AACCDD ##CCDD \" p1 + p2 + p3 + p4 + plot_layout(design = layout) layout <- c( area(t = 2, l = 1, b = 5, r = 4), area(t = 1, l = 3, b = 3, r = 5) ) p1 + p2 + plot_layout(design = layout) layout <- ' A#B #C# D#E ' wrap_plots(D = p1, C = p2, B = p3, design = layout)"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"fixed-aspect-plots","dir":"Articles > Guides","previous_headings":"","what":"Fixed aspect plots","title":"Controlling Layouts","text":"special case comes assembling plots dealing fixed aspect plots, created coord_fixed(), coord_polar(), coord_sf(). possible simultaneously assign even dimensions align fixed aspect plots. default value widths heights arguments plot_layout() NA, treated specially. general behave just 1null (.e. expand fill available space share evenly 1null panels), row/column occupied fixed aspect plot expand contract order keep aspect plot may thus dimension grid width/heights containing plots without fixed aspect plots. need mix behavior fixed dimensions can use special value -1null behaves NA (unit vectors doesn’t allow NA values). width = unit(c(1, 3, -1), c(\"null\", \"cm\", \"null\") specify one column fills available space, one column fixed 3 cm, one column expands match fixed aspect ratio needed otherwise takes size first column. Contrast setting widths non-NA value: can see, fixed aspect plot keeps aspect ratio, loses axis alignment one directions. solution needed probably dependent specific use case. default optimizes use space. restrictions space optimization. fixed aspect plot take multiple rows columns, one fixed aspect plot conflicts another one, one end using full space.","code":"p_fixed <- ggplot(mtcars) + geom_point(aes(hp, disp)) + ggtitle('Plot F') + coord_fixed() p_fixed + p1 + p2 + p3 p_fixed + p1 + p2 + p3 + plot_layout(widths = 1)"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"avoiding-alignment","dir":"Articles > Guides","previous_headings":"","what":"Avoiding alignment","title":"Controlling Layouts","text":"Patchwork designed ’s utmost align plotting areas, generally sensible order create calm good looking layout sometimes gets way creating want. see two cases. situation answer wrap_elements() function.","code":""},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"huge-axis-text-causing-white-space-","dir":"Articles > Guides","previous_headings":"Avoiding alignment","what":"Huge axis text causing white space.","title":"Controlling Layouts","text":"Sometimes one plots much longer axis text axis labels : Depending prefer might want leftmost plot fill much room possible instead aligned rightmost panel. Putting ggplot patchwork inside free() removes alignment plot.","code":"p2mod <- p2 + labs(x = \"This is such a long\\nand important label that\\nit has to span many lines\") p1 | p2mod free(p1) | p2mod"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"designs-dont-keep-an-even-width","dir":"Articles > Guides","previous_headings":"Avoiding alignment","what":"Designs don’t keep an even width","title":"Controlling Layouts","text":"creating complex layout using design may create setups plots spans edge plots surprised affects width panels design: see 3 bottom columns different widths despite given amount space design matrix. reason top plot y-axis left guide right, fall two columns make 1st 3rd column bottom. Subsequently plots expanded fill space. free() save us :","code":"design <- \"#AAAA# #AAAA# BBCCDD EEFFGG\" p3 + p2 + p1 + p4 + p4 + p1 + p2 + plot_layout(design = design) free(p3) + p2 + p1 + p4 + p4 + p1 + p2 + plot_layout(design = design)"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"more-freeing","dir":"Articles > Guides","previous_headings":"Avoiding alignment","what":"More freeing","title":"Controlling Layouts","text":"free() just un-align whole panel. can use side argument control sides align. instruct patchwork free left side ridiculous amount significant digits, keep remaining sides aligned free() also two modes besides default. One free alignment axis labels stick axis: free content outside panel claiming space. instance, plot, need top plot claim space ’s wide y-axis lot empty space left: Using type = \"space\" fix :","code":"p3_very_precise <- p3 + scale_y_continuous(labels = \\(x) format(as.numeric(x), nsmall = 10)) p1 / free(p3_very_precise, side = \"l\") free(p1, type = \"label\") / p3_very_precise plot_spacer() + p3_very_precise + p1 + p2 plot_spacer() + free(p3_very_precise, type = \"space\", side = \"l\") + p1 + p2"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"insets","dir":"Articles > Guides","previous_headings":"","what":"Insets","title":"Controlling Layouts","text":"alternative placing plots grid place plot inset another plot. saw , achievable setting layout multiple overlapping area() specifications. However, approach still uses underlying grid, may constraining. Another approach use inset_element() function marks plot graphic object placed inset previous plot. thus take slot provided layout, share slot previous plot. inset_element() allows freely position inset relative either panel, plot, full area previous plot, specifying location left, bottom, right, top edge inset. location can specified either numerics like grid units. specified numerics converted 'npc' units goes 0 1 specified area. example place inset exactly 1 cm panel border code : , inset_element() allows place inset previous plot, choose , controlling clipping tagging way wrap_elements().","code":"p1 + inset_element(p2, left = 0.6, bottom = 0.6, right = 1, top = 1) p1 + inset_element(p2, left = 0, bottom = 0.6, right = 0.4, top = 1, align_to = 'full') p1 + inset_element( p2, left = 0.5, bottom = 0.5, right = unit(1, 'npc') - unit(1, 'cm'), top = unit(1, 'npc') - unit(1, 'cm') ) p3 + inset_element(p1, left = 0.5, bottom = 0, right = 1, top = 0.5, on_top = FALSE, align_to = 'full')"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"controlling-guides","dir":"Articles > Guides","previous_headings":"","what":"Controlling guides","title":"Controlling Layouts","text":"Plots often guides help viewers deduce aesthetic mapping. composing plots need think . default behavior leave alone simply let follow plot around. Examples can seen color guide always positioned beside Plot 3. behavior fine purpose simply position bunch otherwise unrelated plots next . purpose composition create new tightly coupled visualization, presence guides plots can jarring, though. plot_layout() function provides guides argument controls guides treated. show works, let’s see happens set 'collect': can see guide hoisted placed beside plots. alternative 'collect' 'keep', makes sure guides kept next plot. default value 'auto', sort . collect guides, patchwork nested inside another patchwork patchwork collect guides, allowed hoist . see effect, compare two plots: guide collection another trick sleeve. multiple plots provide guide, don’t want show multiple times. collecting guides compare remove duplicates. Guides compared graphical representation, declarative specification. means different theming among plots may mean two guides showing information merged. Now end empty area grid. Instead leaving empty, can specify place put collected guides, using guide_area() placeholder. works much plot_spacer(), guides collected exactly . guides collected placed instead theme tells . Guide areas accessible nesting level. nested patchwork guide area possible place guides collected higher level .","code":"p1 + p2 + p3 + p4 + plot_layout(guides = 'collect') ((p2 / p3 + plot_layout(guides = 'auto')) | p1) + plot_layout(guides = 'collect') ((p2 / p3 + plot_layout(guides = 'keep')) | p1) + plot_layout(guides = 'collect') p1a <- ggplot(mtcars) + geom_point(aes(mpg, disp, colour = mpg, size = wt)) + ggtitle('Plot 1a') p1a | (p2 / p3) (p1a | (p2 / p3)) + plot_layout(guides = 'collect') p1 + p2 + p3 + guide_area() + plot_layout(guides = 'collect')"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"controlling-axes","dir":"Articles > Guides","previous_headings":"","what":"Controlling Axes","title":"Controlling Layouts","text":"Much like legends , axes can sometimes shared plots. However, makes sense plots positioned besides top exact axis. patchwork provides two arguments plot_layout() controlling axes work much like guides argument except don’t allow recursing nested patchworks (obvious reasons). plot y-axis redundant kept side like used faceted plots: easily fixed axes argument default axis title follows collecting setting axis. also collect titles makes lot sense axes doesn’t match exactly still share title. , title collecting also work direction: see y-axis title now appears positioned centrally.","code":"p1 + p2 p1 + p2 + plot_layout(axes = \"collect\") p1 + p2 + plot_layout(axis_titles = \"collect\") p1 / p2 + plot_layout(axis_titles = \"collect\")"},{"path":"https://patchwork.data-imaginist.com/articles/guides/layout.html","id":"want-more","dir":"Articles > Guides","previous_headings":"","what":"Want more?","title":"Controlling Layouts","text":"layouts. still patchwork. Explore guides learn annotations, special operators multipage alignment.","code":""},{"path":"https://patchwork.data-imaginist.com/articles/guides/multipage.html","id":"want-more","dir":"Articles > Guides","previous_headings":"","what":"Want more?","title":"Alignment Across Multiple Pages","text":"Multipage alignment just small part patchwork. Check guides learn assembling plots, specifying layouts, annotating results.","code":""},{"path":"https://patchwork.data-imaginist.com/articles/patchwork.html","id":"example-plots","dir":"Articles","previous_headings":"","what":"Example plots","title":"Getting Started","text":"’ll start creating example plots use throughout tutorial: plots fairly meaningless serve illustrate plot composition - don’t read anything resulting plots.","code":"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')"},{"path":"https://patchwork.data-imaginist.com/articles/patchwork.html","id":"basic-use","dir":"Articles","previous_headings":"","what":"Basic use","title":"Getting Started","text":"absolute simplest use extension + operator used ggplot2, allow adding plots together: adding plots together, last added plot active one, receive addition new ggplot2 objects geoms, labels, etc:","code":"p1 + p2 p1 + p2 + labs(subtitle = 'This will appear in the last plot')"},{"path":"https://patchwork.data-imaginist.com/articles/patchwork.html","id":"controlling-layout","dir":"Articles","previous_headings":"","what":"Controlling layout","title":"Getting Started","text":"default, patchwork try keep grid square, fill row order can controlled addition plot_layout() plot_layout() sorts amazing features controlling layout composition. See Layout vignette full rundown options.","code":"p1 + p2 + p3 + p4 p1 + p2 + p3 + p4 + plot_layout(nrow = 3, byrow = FALSE)"},{"path":"https://patchwork.data-imaginist.com/articles/patchwork.html","id":"stacking-and-packing-plots","dir":"Articles","previous_headings":"","what":"Stacking and packing plots","title":"Getting Started","text":"Often want place plots top , beside , rather fill grid. can accomplished adding one-row one-column layout, patchwork also provides two operators directly provides visual cues layout. | place plots beside , / stack : patchworks can nested, two operators often enough create rather complex layouts:","code":"p1 / p2 p1 | (p2 / p3)"},{"path":"https://patchwork.data-imaginist.com/articles/patchwork.html","id":"annotating-the-composition","dir":"Articles","previous_headings":"","what":"Annotating the composition","title":"Getting Started","text":"often necessary add titles, captions, tags, etc. composition. can achieved adding plot_annotation() patchwork: Patchwork also provides auto-tagging capabilities, order identify subplots text: tagging can either arabic roman numbers, latin letters, separate tags can given different nesting levels. See Annotation vignette information.","code":"(p1 | (p2 / p3)) + plot_annotation(title = 'The surprising story about mtcars') p1 + p2 + p3 + plot_annotation(tag_levels = 'I')"},{"path":"https://patchwork.data-imaginist.com/articles/patchwork.html","id":"want-more","dir":"Articles","previous_headings":"","what":"Want more?","title":"Getting Started","text":"enough get started, scratched surface patchwork capable . Look guides find , e.g. collect legends one place remove duplicates aligning plots across multiple pages.","code":""},{"path":"https://patchwork.data-imaginist.com/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Thomas Lin Pedersen. Maintainer, author.","code":""},{"path":"https://patchwork.data-imaginist.com/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Pedersen T (2024). patchwork: Composer Plots. R package version 1.3.0, https://github.com/thomasp85/patchwork, https://patchwork.data-imaginist.com.","code":"@Manual{, title = {patchwork: The Composer of Plots}, author = {Thomas Lin Pedersen}, year = {2024}, note = {R package version 1.3.0, https://github.com/thomasp85/patchwork}, url = {https://patchwork.data-imaginist.com}, }"},{"path":"https://patchwork.data-imaginist.com/index.html","id":"patchwork-","dir":"","previous_headings":"","what":"The Composer of Plots","title":"The Composer of Plots","text":"goal patchwork make ridiculously simple combine separate ggplots graphic. tries solve problem gridExtra::grid.arrange() cowplot::plot_grid using API incites exploration iteration, scales arbitrarily complex layouts.","code":""},{"path":"https://patchwork.data-imaginist.com/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"The Composer of Plots","text":"can install patchwork CRAN using install.packages('patchwork'). Alternatively can grab development version github using devtools:","code":"# install.packages(\"devtools\") devtools::install_github(\"thomasp85/patchwork\")"},{"path":"https://patchwork.data-imaginist.com/index.html","id":"basic-example","dir":"","previous_headings":"","what":"Basic example","title":"The Composer of Plots","text":"usage patchwork simple: just add plots together! patchwork provides rich support arbitrarily complex layouts full alignment. example, check readable code nesting three plots top third:","code":"library(ggplot2) library(patchwork) p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p1 + p2 p3 <- ggplot(mtcars) + geom_smooth(aes(disp, qsec)) p4 <- ggplot(mtcars) + geom_bar(aes(carb)) (p1 | p2 | p3) / p4"},{"path":"https://patchwork.data-imaginist.com/index.html","id":"learn-more","dir":"","previous_headings":"","what":"Learn more","title":"The Composer of Plots","text":"patchwork can much . Check guides learning everything know different features: Getting Started Assembling Plots Defining Layouts Adding Annotation Aligning across pages","code":""},{"path":"https://patchwork.data-imaginist.com/index.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"The Composer of Plots","text":"Please note patchwork project released Contributor Code Conduct. contributing project, agree abide terms.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/align_plots.html","id":null,"dir":"Reference","previous_headings":"","what":"Deprecated functions — align_plots","title":"Deprecated functions — align_plots","text":"functions deprecated used.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/area.html","id":null,"dir":"Reference","previous_headings":"","what":"Specify a plotting area in a layout — area","title":"Specify a plotting area in a layout — area","text":"small helper used specify single area rectangular grid contain plot. Objects constructed area() can concatenated together c() order specify multiple areas.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/area.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Specify a plotting area in a layout — area","text":"","code":"area(t, l, b = t, r = l)"},{"path":"https://patchwork.data-imaginist.com/reference/area.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Specify a plotting area in a layout — area","text":"t, b top bottom bounds area grid l, r left right bounds area int grid","code":""},{"path":"https://patchwork.data-imaginist.com/reference/area.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Specify a plotting area in a layout — area","text":"patch_area object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/area.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Specify a plotting area in a layout — area","text":"grid areas specified reference enumerate rows top bottom, coloumns left right. means t l always less equal b r respectively. Instead specifying area placement combination area() calls, possible instead pass single string equivalent example , see plot_layout() examples.","code":"areas <- c(area(1, 1, 2, 1), area(2, 3, 3, 3)) areas < -\"A## A#B ##B\""},{"path":"https://patchwork.data-imaginist.com/reference/area.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Specify a plotting area in a layout — area","text":"","code":"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)"},{"path":"https://patchwork.data-imaginist.com/reference/free.html","id":null,"dir":"Reference","previous_headings":"","what":"Free a plot from various alignments — free","title":"Free a plot from various alignments — free","text":"purpose patchwork often align plots various parts, sometimes cut want compose plots without alignment. free() function tells patchwork treat content (can either ggplot patchwork) specially align remaining plots composition. free() various modes control type \"non-alignment\" applied (see Details). can control side plot non-alignment applied . can stack free() calls e.g. want top part align panel left part align labels.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/free.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Free a plot from various alignments — free","text":"","code":"free(x, type = c(\"panel\", \"label\", \"space\"), side = \"trbl\")"},{"path":"https://patchwork.data-imaginist.com/reference/free.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Free a plot from various alignments — free","text":"x ggplot patchwork object type type freeing applied. See Details section side side freeing applied . string containing one \"t\", \"r\", \"b\", \"l\"","code":""},{"path":"https://patchwork.data-imaginist.com/reference/free.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Free a plot from various alignments — free","text":"modified version x free_plot class","code":""},{"path":"https://patchwork.data-imaginist.com/reference/free.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Free a plot from various alignments — free","text":"free() multiple modes depending needing: default \"panel\" allow panel area ignore alginment remaining plots expand much needed fill empty space. \"label\" type instead free axis label keep proximity axis, even longer axis text another plot push apart. \"space\" type also keeps axis title together, instead reserve space . allows axis occupy space otherwise empty area without making additional space available .","code":""},{"path":"https://patchwork.data-imaginist.com/reference/free.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Free a plot from various alignments — free","text":"","code":"# 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 (here, with the default \"panel\" type) free(p1) / p2 # If we still want the panels to be aligned to the right, we can choose to # free only the left side free(p1, side = \"l\") / p2 # We can still collect guides like before free(p1) / p2 + plot_layout(guides = \"collect\") # We could use \"label\" to fix the layout in a different way p1 / free(p2, \"label\") # Another issue is that long labels are not using already available free # space. plot_spacer() + p1 + p2 + p2 # This can be fixed with the \"space\" type plot_spacer() + free(p1, \"space\", \"l\") + p2 + p2"},{"path":"https://patchwork.data-imaginist.com/reference/guide_area.html","id":null,"dir":"Reference","previous_headings":"","what":"Add an area to hold collected guides — guide_area","title":"Add an area to hold collected guides — guide_area","text":"Using guides argument plot_layout() can collect collapse guides plots. default guides put side like regular plots, adding guide_area() plot can tell patchwork place guides area instead. guides collected guides exists collect behaves standard plot_spacer() instead.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/guide_area.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add an area to hold collected guides — guide_area","text":"","code":"guide_area()"},{"path":"https://patchwork.data-imaginist.com/reference/guide_area.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add an area to hold collected guides — guide_area","text":"","code":"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')"},{"path":"https://patchwork.data-imaginist.com/reference/inset_element.html","id":null,"dir":"Reference","previous_headings":"","what":"Create an inset to be added on top of the previous plot — inset_element","title":"Create an inset to be added on top of the previous plot — inset_element","text":"standard approach patchwork place plots next based provided layout. However, may sometimes beneficial place one several plots graphic elements freely top another plot. inset_element() function provides way create insets gives full control placement.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/inset_element.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create an inset to be added on top of the previous plot — inset_element","text":"","code":"inset_element( p, left, bottom, right, top, align_to = \"panel\", on_top = TRUE, clip = TRUE, ignore_tag = FALSE )"},{"path":"https://patchwork.data-imaginist.com/reference/inset_element.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create an inset to be added on top of the previous plot — inset_element","text":"p grob, ggplot, patchwork, formula, raster, nativeRaster, gt object add inset left, bottom, right, top numerics units giving location outer bounds. given numerics converted npc units. align_to Specifies left, bottom, etc relative . Either 'panel' (default), 'plot', 'full'. on_top Logical. inset placed top plot (background)? clip Logical. clipping performed inset? ignore_tag Logical. autotagging ignore inset?","code":""},{"path":"https://patchwork.data-imaginist.com/reference/inset_element.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create an inset to be added on top of the previous plot — inset_element","text":"inset_path object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/inset_element.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create an inset to be added on top of the previous plot — inset_element","text":"","code":"library(ggplot2) p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) # Basic use p1 + inset_element(p2, 0.6, 0.6, 1, 1) # Align to the full area instead p1 + inset_element(p2, 0, 0.6, 0.4, 1, align_to = 'full') # Grobs and other objects can be added as insets as well p1 + inset_element(grid::circleGrob(), 0.4, 0.4, 0.6, 0.6) if (requireNamespace('png', quietly = TRUE)) { logo <- system.file('help', 'figures', 'logo.png', package = 'patchwork') logo <- png::readPNG(logo, native = TRUE) p1 + inset_element(logo, 0.8, 0.8, 1, 1, align_to = 'full') } # Just as expected insets are still amenable to changes after the fact p1 + inset_element(p2, 0.6, 0.6, 1, 1) + theme_classic() # Tagging also continues to work as expected p1 + inset_element(p2, 0.6, 0.6, 1, 1) + plot_annotation(tag_levels = '1') # but can be turned off, like for wrapped plots p1 + inset_element(p2, 0.6, 0.6, 1, 1, ignore_tag = TRUE) + plot_annotation(tag_levels = '1')"},{"path":"https://patchwork.data-imaginist.com/reference/multipage_align.html","id":null,"dir":"Reference","previous_headings":"","what":"Align plots across multiple pages — multipage_align","title":"Align plots across multiple pages — multipage_align","text":"Sometimes necessary make sure separate plots aligned, , still exists separate plots. e.g. need part slideshow want titles panels jumping around switch slides. patchwork provides range utilities achieve . Currently possible align ggplots, aligning patchworks supported future.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/multipage_align.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Align plots across multiple pages — multipage_align","text":"","code":"get_dim(plot) set_dim(plot, dim) get_max_dim(...) align_patches(...)"},{"path":"https://patchwork.data-imaginist.com/reference/multipage_align.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Align plots across multiple pages — multipage_align","text":"plot ggplot object dim plot_dimension object created get_dim() ... ggplot objects single list ","code":""},{"path":"https://patchwork.data-imaginist.com/reference/multipage_align.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Align plots across multiple pages — multipage_align","text":"get_dim() get_max_dim() return plot_dimension object. set_dim() returns modified ggplot object fixed outer dimensions align_patches() return list . modified ggplots still behaves like standard ggplot new layers, scales, etc can added .","code":""},{"path":"https://patchwork.data-imaginist.com/reference/multipage_align.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Align plots across multiple pages — multipage_align","text":"","code":"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()"},{"path":"https://patchwork.data-imaginist.com/reference/patchGrob.html","id":null,"dir":"Reference","previous_headings":"","what":"Get a grob describing the content of a patch object — patchGrob","title":"Get a grob describing the content of a patch object — patchGrob","text":"Methods generic defined patch subclasses return compliant gtable object ready combined regular plot objects. general best call patch_table() object add grobs patch_table() return compliant gtable","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchGrob.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get a grob describing the content of a patch object — patchGrob","text":"","code":"patchGrob(x, guides = \"auto\")"},{"path":"https://patchwork.data-imaginist.com/reference/patchGrob.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get a grob describing the content of a patch object — patchGrob","text":"x patch object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchGrob.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get a grob describing the content of a patch object — patchGrob","text":"gtable object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchwork-package.html","id":null,"dir":"Reference","previous_headings":"","what":"patchwork: The Composer of Plots — patchwork-package","title":"patchwork: The Composer of Plots — patchwork-package","text":"'ggplot2' package provides strong API sequentially building plot, concern composition multiple plots. 'patchwork' package expands API allow arbitrarily complex composition plots , among others, providing mathematical operators combining multiple plots. packages try address need (different approach) 'gridExtra' 'cowplot'.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchwork-package.html","id":"overview","dir":"Reference","previous_headings":"","what":"Overview","title":"patchwork: The Composer of Plots — patchwork-package","text":"use premise patchwork simple: Just add ggplot2 plots together compose multiplot layouts. simplicity much say. Still, functions allow modify behaviour, e.g.: plot_layout() allows define grid plots put plot_annotation() allows add titles, tags etc.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchwork-package.html","id":"learn-more","dir":"Reference","previous_headings":"","what":"Learn more","title":"patchwork: The Composer of Plots — patchwork-package","text":"guides teach can patchwork. Getting Started Assembling Plots Defining Layouts Adding Annotation Aligning across pages","code":""},{"path":[]},{"path":"https://patchwork.data-imaginist.com/reference/patchwork-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"patchwork: The Composer of Plots — patchwork-package","text":"Maintainer: Thomas Lin Pedersen thomasp85@gmail.com (ORCID)","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchwork-package.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"patchwork: The Composer of Plots — patchwork-package","text":"","code":"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))"},{"path":"https://patchwork.data-imaginist.com/reference/patchworkGrob.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert a patchwork to a gtable — patchworkGrob","title":"Convert a patchwork to a gtable — patchworkGrob","text":"function patchwork analogue ggplot2::ggplotGrob() takes unevaluated patchwork object fixate gtable object manipulate directly.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchworkGrob.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert a patchwork to a gtable — patchworkGrob","text":"","code":"patchworkGrob(x)"},{"path":"https://patchwork.data-imaginist.com/reference/patchworkGrob.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert a patchwork to a gtable — patchworkGrob","text":"x patchwork object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/patchworkGrob.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert a patchwork to a gtable — patchworkGrob","text":"gtable object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_annotation.html","id":null,"dir":"Reference","previous_headings":"","what":"Annotate the final patchwork — plot_annotation","title":"Annotate the final patchwork — plot_annotation","text":"result function can added patchwork using + way plot_layout(), unlike plot_layout() effect top level plot. name suggests controls different aspects annotation final plot, titles tags. Already added annotations can removed setting relevant argument NULL.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_annotation.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Annotate the final patchwork — plot_annotation","text":"","code":"plot_annotation( title = waiver(), subtitle = waiver(), caption = waiver(), tag_levels = waiver(), tag_prefix = waiver(), tag_suffix = waiver(), tag_sep = waiver(), theme = waiver() )"},{"path":"https://patchwork.data-imaginist.com/reference/plot_annotation.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Annotate the final patchwork — plot_annotation","text":"title, subtitle, caption Text strings use various plot annotations. tag_levels character vector defining enumeration format use level. Possible values '' lowercase letters, '' uppercase letters, '1' numbers, '' lowercase Roman numerals, '' uppercase Roman numerals. can also list containing character vectors defining arbitrary tag sequences. element list scalar one '', '', '1', ', '', level expanded expected sequence. tag_prefix, tag_suffix Strings appear tag. tag_sep separator different tag levels theme ggplot theme specification use plot. elements related titles well plot margin background used.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_annotation.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Annotate the final patchwork — plot_annotation","text":"plot_annotation object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_annotation.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Annotate the final patchwork — plot_annotation","text":"Tagging subplots done automatically following order plots added. plot contains nested layouts tag_level argument nested plot_layout define whether enumeration continue usual add new level. format levels defined tag_levels argument plot_annotation","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_annotation.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Annotate the final patchwork — plot_annotation","text":"","code":"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) # Add title, etc. to a patchwork p1 + p2 + plot_annotation('This is a title', caption = 'made with patchwork') # Change styling of patchwork elements p1 + p2 + plot_annotation( title = 'This is a title', caption = 'made with patchwork', theme = theme(plot.title = element_text(size = 16)) ) # Add tags to plots p1 / (p2 | p3) + plot_annotation(tag_levels = 'A') # Add multilevel tagging to nested layouts p1 / ((p2 | p3) + plot_layout(tag_level = 'new')) + plot_annotation(tag_levels = c('A', '1')) # Use a custom tag sequence (mixed with a standard one) p1 / ((p2 | p3) + plot_layout(tag_level = 'new')) + plot_annotation(tag_levels = list(c('&', '%'), '1'))"},{"path":"https://patchwork.data-imaginist.com/reference/plot_arithmetic.html","id":null,"dir":"Reference","previous_headings":"","what":"Plot arithmetic — plot_arithmetic","title":"Plot arithmetic — plot_arithmetic","text":"addition + operator known ggplot2, patchwork defines logic operators aids building plot composition reduce code-reuse.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_arithmetic.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Plot arithmetic — plot_arithmetic","text":"","code":"# S3 method for class 'ggplot' e1 - e2 # S3 method for class 'ggplot' e1/e2 # S3 method for class 'ggplot' e1 | e2 # S3 method for class 'gg' e1 * e2 # S3 method for class 'gg' e1 & e2"},{"path":"https://patchwork.data-imaginist.com/reference/plot_arithmetic.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Plot arithmetic — plot_arithmetic","text":"e1 ggplot patchwork object e2 ggplot patchwork object case /, gg object geom theme specification case * &","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_arithmetic.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Plot arithmetic — plot_arithmetic","text":"patchwork object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_arithmetic.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Plot arithmetic — plot_arithmetic","text":"patchwork augment + operator ggplot2 allows user add full ggplot objects together order compose view. last added plot always active one new geoms etc. added . Another operator much like , quite, -. also adds plots together instead adding right hand side patchwork defined left hand side, puts left hand side besides right hand side patchwork. might sound confusing, essence - ensures right left side put nesting level (+ puts right side left side). Using - might seem unintuitive think operator \"subtract\", look hyphen instead (underlying reason - operator precedence group +). alternative explicit way get effect - use merge() left hand side. Often interested creating single column single row layouts. patchwork provides | (besides) / () operators support stacking packing plots. See examples use. order reduce code repetition patchwork provides two operators adding ggplot elements (geoms, themes, facets, etc.) multiple/plots patchwork. * add element plots current nesting level, & recurse nested patches.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_arithmetic.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Plot arithmetic — plot_arithmetic","text":"","code":"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)) # Standard addition vs division p1 + p2 + p3 + plot_layout(ncol = 1) p1 + p2 - p3 + plot_layout(ncol = 1) # Stacking and packing (p1 | p2 | p3) / p4 # Add elements to the same nesting level (p1 + (p2 + p3) + p4 + plot_layout(ncol = 1)) * theme_bw() # Recurse into nested plots as well (p1 + (p2 + p3) + p4 + plot_layout(ncol = 1)) & theme_bw()"},{"path":"https://patchwork.data-imaginist.com/reference/plot_layout.html","id":null,"dir":"Reference","previous_headings":"","what":"Define the grid to compose plots in — plot_layout","title":"Define the grid to compose plots in — plot_layout","text":"control different plots laid , need add layout specification. nesting grids, layout scoped current nesting level. already set value can removed setting NULL.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_layout.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Define the grid to compose plots in — plot_layout","text":"","code":"plot_layout( ncol = waiver(), nrow = waiver(), byrow = waiver(), widths = waiver(), heights = waiver(), guides = waiver(), tag_level = waiver(), design = waiver(), axes = waiver(), axis_titles = axes )"},{"path":"https://patchwork.data-imaginist.com/reference/plot_layout.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Define the grid to compose plots in — plot_layout","text":"ncol, nrow dimensions grid create - NULL use logic facet_wrap() set dimensions byrow Analogous byrow matrix(). FALSE plots filled column-major order widths, heights relative widths heights column row grid. get repeated match dimensions grid. special value NA/-1null behave 1null unless fixed aspect plot inserted case allow dimension expand contract match aspect ratio content guides string specifying guides treated layout. 'collect' collect guides given nesting level, removing duplicates. 'keep' stop collection level let guides placed alongside plot. auto allow guides collected upper level tries, place alongside plot . modify default guide \"position\" theme(legend.position=...) also collecting guides must apply change overall patchwork (see example). tag_level string ('keep' 'new') indicate auto-tagging behave. See plot_annotation(). design Specification location areas layout. Can either specified text string concatenating calls area() together. See examples information use. axes string specifying axes treated. 'keep' retain axes individual plots. 'collect' remove duplicated axes placed run rows columns layout. 'collect_x' 'collect_y' remove duplicated x-axes columns duplicated y-axes rows respectively. axis_titles string specifying axis titltes treated. 'keep' retain axis titles individual plots. 'collect' remove duplicated titles one direction merge titles opposite direction. 'collect_x' 'collect_y' control x-axis titles y-axis titles respectively.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_layout.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Define the grid to compose plots in — plot_layout","text":"plot_layout object added ggassmble object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_layout.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Define the grid to compose plots in — plot_layout","text":"","code":"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')"},{"path":"https://patchwork.data-imaginist.com/reference/plot_spacer.html","id":null,"dir":"Reference","previous_headings":"","what":"Add a completely blank area — plot_spacer","title":"Add a completely blank area — plot_spacer","text":"simple wrapper creates empty transparent patch can added push plots apart. patch responds adding theme() specifications, plot.background effect.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_spacer.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add a completely blank area — plot_spacer","text":"","code":"plot_spacer()"},{"path":"https://patchwork.data-imaginist.com/reference/plot_spacer.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add a completely blank area — plot_spacer","text":"ggplot object containing empty plot","code":""},{"path":"https://patchwork.data-imaginist.com/reference/plot_spacer.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add a completely blank area — plot_spacer","text":"","code":"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\")))"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_elements.html","id":null,"dir":"Reference","previous_headings":"","what":"Wrap arbitrary graphics in a patchwork-compliant patch — wrap_elements","title":"Wrap arbitrary graphics in a patchwork-compliant patch — wrap_elements","text":"order add non-ggplot2 element patchwork can converted compliant representation using wrap_elements() function. allows position either grobs, ggplot objects, patchwork objects, even base graphics (passed formula) either full area, full plotting area (anything including axis label), panel area (actual area data drawn). can still add title, subtitle, tag, caption using approach normal ggplots (using ggtitle() labs()) well styling using theme(). latter, theme elements targeting plot margins background well title, subtitle, etc styling effect. patchwork ggplot object wrapped, fixated state longer respond addition styling, geoms, etc.. grobs formulas added directly, implicitly converted wrap_elements(full = x).","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_elements.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Wrap arbitrary graphics in a patchwork-compliant patch — wrap_elements","text":"","code":"wrap_elements( panel = NULL, plot = NULL, full = NULL, clip = TRUE, ignore_tag = FALSE )"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_elements.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Wrap arbitrary graphics in a patchwork-compliant patch — wrap_elements","text":"panel, plot, full grob, ggplot, patchwork, formula, raster, nativeRaster, gt object add respective area. clip grobs clipped expanding outside area ignore_tag tags ignored patch. relevant using automatic tagging plots content patch qualify tag.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_elements.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Wrap arbitrary graphics in a patchwork-compliant patch — wrap_elements","text":"wrapped_patch object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_elements.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Wrap arbitrary graphics in a patchwork-compliant patch — wrap_elements","text":"","code":"library(ggplot2) library(grid) # Combine grobs with each other wrap_elements(panel = textGrob('Here are some text')) + wrap_elements( panel = rectGrob(gp = gpar(fill = 'steelblue')), full = rectGrob(gp = gpar(fill = 'goldenrod')) ) # wrapped elements can still get titles etc like ggplots wrap_elements(panel = textGrob('Here are some text')) + wrap_elements( panel = rectGrob(gp = gpar(fill = 'steelblue')), full = rectGrob(gp = gpar(fill = 'goldenrod')) ) + ggtitle('Title for the amazing rectangles') # You can also pass in ggplots or patchworks to e.g. have it fill out the # panel area p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p1 + wrap_elements(panel = p1 + ggtitle('Look at me shrink')) # You can even add base graphics if you pass it as a formula (requires gridGraphics package) if (requireNamespace(\"gridGraphics\", quietly = TRUE)) { p1 + wrap_elements(full = ~ plot(mtcars$mpg, mtcars$disp)) # Adding a grob or formula directly is equivalent to placing it in `full` p1 + ~ plot(mtcars$mpg, mtcars$disp) }"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_ggplot_grob.html","id":null,"dir":"Reference","previous_headings":"","what":"Make a gtable created from a ggplot object patchwork compliant — wrap_ggplot_grob","title":"Make a gtable created from a ggplot object patchwork compliant — wrap_ggplot_grob","text":"function converts gtable, produced ggplot2::ggplotGrob() makes ready added patchwork. contrast passing gtable wrap_elements(), wrap_ggplot_grob() ensures proper alignment expected. hand major restructuring gtable result object work properly wrap_ggplot_grob().","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_ggplot_grob.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Make a gtable created from a ggplot object patchwork compliant — wrap_ggplot_grob","text":"","code":"wrap_ggplot_grob(x)"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_ggplot_grob.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Make a gtable created from a ggplot object patchwork compliant — wrap_ggplot_grob","text":"x gtable produced ggplot2::ggplotGrob()","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_ggplot_grob.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Make a gtable created from a ggplot object patchwork compliant — wrap_ggplot_grob","text":"table_patch object added patchwork","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_ggplot_grob.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Make a gtable created from a ggplot object patchwork compliant — wrap_ggplot_grob","text":"","code":"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)"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_plots.html","id":null,"dir":"Reference","previous_headings":"","what":"Wrap plots into a patchwork — wrap_plots","title":"Wrap plots into a patchwork — wrap_plots","text":"use + natural way add plots together, can difficult string together multiple plots programmatically number plots known beforehand. wrap_plots makes easy take list plots add one composition, along layout specifications.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_plots.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Wrap plots into a patchwork — wrap_plots","text":"","code":"wrap_plots( ..., ncol = NULL, nrow = NULL, byrow = NULL, widths = NULL, heights = NULL, guides = NULL, tag_level = NULL, design = NULL, axes = NULL, axis_titles = axes )"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_plots.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Wrap plots into a patchwork — wrap_plots","text":"... multiple ggplots list containing ggplot objects ncol, nrow dimensions grid create - NULL use logic facet_wrap() set dimensions byrow Analogous byrow matrix(). FALSE plots filled column-major order widths, heights relative widths heights column row grid. get repeated match dimensions grid. special value NA/-1null behave 1null unless fixed aspect plot inserted case allow dimension expand contract match aspect ratio content guides string specifying guides treated layout. 'collect' collect guides given nesting level, removing duplicates. 'keep' stop collection level let guides placed alongside plot. auto allow guides collected upper level tries, place alongside plot . modify default guide \"position\" theme(legend.position=...) also collecting guides must apply change overall patchwork (see example). tag_level string ('keep' 'new') indicate auto-tagging behave. See plot_annotation(). design Specification location areas layout. Can either specified text string concatenating calls area() together. See examples information use. axes string specifying axes treated. 'keep' retain axes individual plots. 'collect' remove duplicated axes placed run rows columns layout. 'collect_x' 'collect_y' remove duplicated x-axes columns duplicated y-axes rows respectively. axis_titles string specifying axis titltes treated. 'keep' retain axis titles individual plots. 'collect' remove duplicated titles one direction merge titles opposite direction. 'collect_x' 'collect_y' control x-axis titles y-axis titles respectively.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_plots.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Wrap plots into a patchwork — wrap_plots","text":"patchwork object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_plots.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Wrap plots into a patchwork — wrap_plots","text":"design specified text string plots named (e.g. wrap_plots(= p1, ...)) plot names single characters represented design layout string, plots matched respective area name. Otherwise areas filled sequentially manner using + operator. See examples .","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_plots.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Wrap plots into a patchwork — wrap_plots","text":"","code":"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)) # Either add the plots as single arguments wrap_plots(p1, p2, p3, p4, p5) # Or add them as a list... plots <- list(p1, p2, p3, p4, p5) wrap_plots(plots) # Match plots to areas by name design <- \"#BB AA#\" wrap_plots(B = p1, A = p2, design = design) # Compare to not using named plot arguments wrap_plots(p1, p2, design = design)"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_table.html","id":null,"dir":"Reference","previous_headings":"","what":"Wrap a table in a patchwork compliant patch — wrap_table","title":"Wrap a table in a patchwork compliant patch — wrap_table","text":"function works much like wrap_elements() turns input patchwork compliant objects can added composition. However, wrap_table() uses knowledge input table provide nifty layout options makes generally better use wrap_elements() type object.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_table.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Wrap a table in a patchwork compliant patch — wrap_table","text":"","code":"wrap_table( table, panel = c(\"body\", \"full\", \"rows\", \"cols\"), space = c(\"free\", \"free_x\", \"free_y\", \"fixed\"), ignore_tag = FALSE )"},{"path":"https://patchwork.data-imaginist.com/reference/wrap_table.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Wrap a table in a patchwork compliant patch — wrap_table","text":"table gt table object coercible data frame panel portion table aligned panel region? \"body\" means column row headers placed outside panel region, .e. topleft corner panel region aligned topleft data cell. \"full\" means whole table placed inside panel region. \"rows\" means rows (including column headers) placed inside panel region row headers placed left. \"cols\" opposite, placing columns within panel region keeping column header top . set \"body\" \"cols\" space set \"fixed\" \"free_x\" footnotes source notes table placed outside bottom panel region. space dimension table influence final composition? \"fixed\" means table width set width column occupies table height set height row occupies. \"free\" opposite meaning table dimension influence sizing. \"free_x\" \"free_y\" allows free either direction keeping remaining fixed. note set specific width height plot_layout() higher priority table dimensions ignore_tag tags ignored patch. relevant using automatic tagging plots content patch qualify tag.","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_table.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Wrap a table in a patchwork compliant patch — wrap_table","text":"wrapped_table object","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_table.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Wrap a table in a patchwork compliant patch — wrap_table","text":"functionality requires v0.11.0 higher gt package","code":""},{"path":"https://patchwork.data-imaginist.com/reference/wrap_table.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Wrap a table in a patchwork compliant patch — wrap_table","text":"","code":"library(ggplot2) library(gt) p1 <- ggplot(airquality) + geom_line(aes(x = Day, y = Temp, colour = month.name[Month])) + labs(colour = \"Month\") table <- data.frame( Month = month.name[5:9], \"Mean temp.\" = tapply(airquality$Temp, airquality$Month, mean), \"Min temp.\" = tapply(airquality$Temp, airquality$Month, min), \"Max temp.\" = tapply(airquality$Temp, airquality$Month, max) ) gt_tab <- gt(table, rowname_col = \"Month\") # Default addition usees wrap_table p1 + gt_tab # Default places column and row headers outside panel area. Use wrap_table # to control this p1 + wrap_table(gt_tab, panel = \"full\") # Tables generally have fixed dimensions and these can be used to control # the size of the area they occupy p2 <- ggplot(airquality) + geom_boxplot(aes(y = month.name[Month], x = Temp)) + scale_y_discrete(name = NULL, limits = month.name[9:5], guide = \"none\") wrap_table(gt_tab, space = \"fixed\") + p2"},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-130","dir":"Changelog","previous_headings":"","what":"patchwork 1.3.0","title":"patchwork 1.3.0","text":"CRAN release: 2024-09-16 free() now better aligns plots horizontal direction Plot backgrounds now always placed beneath elements patchwork (#370) Axis titles can now reliably collected even faceted plots (#367) Native support gt objects, either adding directly controlling layout wrap_table() Empty patches longer breaks axis title collection (#375) wrap_ggplot_grob() now respects auto-tagging (#363) Fix bug guide collecting prevent proper axes collecting (#359) Fix bug free() tags placed top plot region become missing (#350) free() gains type side argument. first control whether free panel, label, space occupied outside panel, second control sides applies (#345 #379) .list() now provided patchwork objects get plots patchwork list. also allows use lapply() friends patchwork objects (#381) default arguments plot_annotation() plot_layout() now waiver() allowing use NULL remove already set value (#198) Guide axis merging slightly robust comes merging different graphical parameters means used (e.g. “black” “#000000”) (#369) fix bug collecting guides null unit key size (#390) Added nest() explicitly nest patchwork LHS operator","code":""},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-120","dir":"Changelog","previous_headings":"","what":"patchwork 1.2.0","title":"patchwork 1.2.0","text":"CRAN release: 2024-01-08 Axes axis titles can now collected using plot_layout() function. Collecting axes remove duplicated axes x- y-direction. Collecting axis titles also remove duplicated titles x- y-direction, also merge duplicated titles direction (#150). Fix bug prevented faceted plots axes right used (#340) Added free() function mark plot aligned rest. margin plot still aligned margins plots everything inside unaligned.","code":""},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-113","dir":"Changelog","previous_headings":"","what":"patchwork 1.1.3","title":"patchwork 1.1.3","text":"CRAN release: 2023-08-14 NULL can now used different arithmetic operators result non-operation (.e. non-null part returned unmodified) (#290) Fix bug prevented plots multi-level strips merged together (#277) Patchworks now render correctly unserialised fresh session, providing patchwork package available (#242) Fixed bug preventing faceted plots strip placement outside axis aligned (#325) Fixed bug let inconsistent results combining fixed aspect plots different order (#274) Fixed bug prevented nested patchworks empty columns rows bottom right inserted layout (#273) Patchwork objects now behaves correctly like unnamed list ggplots. makes View() work (#317), allow one use length() determine number patches patchwork (#293) Expressions calls can now used plot annotations way can used titles ggplot2 (#295)","code":""},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-112","dir":"Changelog","previous_headings":"","what":"patchwork 1.1.2","title":"patchwork 1.1.2","text":"CRAN release: 2022-08-19 Better error message rendering fails due small plotting space","code":""},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-111","dir":"Changelog","previous_headings":"","what":"patchwork 1.1.1","title":"patchwork 1.1.1","text":"CRAN release: 2020-12-17 Use vdiffr conditionally pass test M1 mac Add str() method patchwork objects (#217) Fix bug inset_element() insetting plots fixed dimensions (#214) Make sure -, /, | works supported object types (#221)","code":""},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-110","dir":"Changelog","previous_headings":"","what":"patchwork 1.1.0","title":"patchwork 1.1.0","text":"CRAN release: 2020-11-09 Add inset_element() allow adding plots insets patchwork now supports raster nativeRaster objects Avoid incrementing tag counter recursing nested plot without additional tags use (#147) Fix bug prevented strips turned element_blank() working (#200) Add option supply custom sequence tags use auto-tagging (#211, #63)","code":""},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-101","dir":"Changelog","previous_headings":"","what":"patchwork 1.0.1","title":"patchwork 1.0.1","text":"CRAN release: 2020-06-22 Renaming align_plots() align_patches() avoid namespace clash cowplot (#130) Renaming as_grob() (unexported) as_patch() avoid potential future namespace clash cowplot (#131) Fix bug plot simplification theme(strip.placement = 'outside') (#132) Fix bug guide collection R >= 4.0 due new unit implementation grid (#170) Collected guides now behave ggplot2 guides position top bottom (#137) Fix bug base graphic support environment plot captured (#138) Fix bug combining plots guides placed manually combination faceting (#144) Fix bug negative margins around legend result unintelligeble error (#148) Fix bug trying combine faceted plots fixed aspect ratio (#156) Fix alignments strips single strip present (#163) Fix bug caused theme void result errors (#180) Make aligning multiple fixed aspect plots consistent (#175)","code":""},{"path":"https://patchwork.data-imaginist.com/news/index.html","id":"patchwork-100","dir":"Changelog","previous_headings":"","what":"patchwork 1.0.0","title":"patchwork 1.0.0","text":"CRAN release: 2019-12-01 First CRAN release. Provide utility operators assembling nesting plots composition, tag subplots, collect guides remove duplicates, align plots across pages.","code":""}]
Pedersen T (2024). patchwork: The Composer of Plots. -R package version 1.2.0.9000, https://github.com/thomasp85/patchwork, https://patchwork.data-imaginist.com. +R package version 1.3.0, https://github.com/thomasp85/patchwork, https://patchwork.data-imaginist.com.
@Manual{, title = {patchwork: The Composer of Plots}, author = {Thomas Lin Pedersen}, year = {2024}, - note = {R package version 1.2.0.9000, https://github.com/thomasp85/patchwork}, + note = {R package version 1.3.0, https://github.com/thomasp85/patchwork}, url = {https://patchwork.data-imaginist.com}, }
CRAN release: 2024-09-16
free()