R Package Review Episode 6: Patchwork
Key Takeaways
Reviews the R package Patchwork
Full Transcript
this whole argument another set of parens and divided by right you can probably guess what's going to happen underneath this whole combination we now have the right chart so you can see how you could nest this and get some really complex [Music] welcome back everyone if you're new here my name is brian jenks and on this channel we talk about all things programming tech data analytics and research today we're going to be talking about the patchwork package it's another r package review and the patchwork package is really useful for abstracting away the formatting of combining multiple charts and plots that are gg plots in r and making the output more organized like a grid pattern or have two on the top and one under the bottom with minimal code patrick achieves this with a math like syntax that's very simple to understand there's not too much to it so it's not going to be very overwhelming and let's get into it so jumping right into rstudio right off the bat what does this package do why should you care ggplots are very good looking graphics and sometimes the code to get them to do certain things is just really difficult to figure out patchwork abstracts this away with a very easy math like syntax to make it easy to combine these plots visually in a layout that is aesthetically pleasing you can see i already have four plots made plus them you know so we're adding them all to each other if i run that it'll add it visually in an overflow grid so this is like an example of something that patchwork can do so we're going to go through all the details how we can lay these things out and just what can this package do for you and what are the different layout options first order of business as always we're going to start with a brand new r session on mac it's going to be ctrl shift f10 or command shift f10 we want to do a brand new r session so that everything is clean brand new clean slate a little bit more housekeeping i have my our markdown document i have some chunk options here for fig height and width this is so the figures are actually big enough for the charts that i made for this this example so they're set to nine inches i got three different libraries being loaded d plier just because i have some filtering going on just for the charts that i made that's its only use patchwork and ggplots this is what we're showing today patchwork works with ggplots on livestream i've tested and it does not work with lattice charts and pretty much all the documentation is pointing to working primarily with ggplot2 createdplots so with that out of the way i made some sample plots using the add-in i frequently use i'm not gonna pronounce it because i butchered every time but when you download this package you get the add-in ggplot2 builder so i just made some very simple plots with the built-in data sets that come with probably plot 2 and rstudio so using those that's why i'm not going to type out all the code randomly today so with this you basically create your plots and once you have the output looking the way that you like it you're going to assign those plots to variables so just to make it easier easier to understand how i'm actually doing this layout i actually named the chart something that makes sense so this first one is going to top the second chart is going to be assigned to the variable bottom and now to semantically do this we're going to say top divided by bottom and that's all we have to do with this syntax you take these gigiplots in variables and you do this math like syntax in the r code chunk area and now when i run this code it will produce two charts with top on top and bottom on the bottom so this is a very simple way of just put these two charts in this type of layout no other weird shenanigans about it let's say you want to put two charts side by side we're going to repeat we're just going to create two sample plots and then we're going to sign them to two different variables left and right and then left plus right so instead of dividing to put it underneath we're going to add it together and it's going to go from left to right and the output is left to right so we have a grid and we have a chord flipped bar chart okay so you might be saying but i don't like having all these things assigned to variables and cluttering up my environment so when you go to your environment pane here in our studio to see all the currently assigned variables data imported and all that stuff you might not want one of these for every single chart that you're dealing with you know that's a that's a fair argument so what you can actually do with patchwork is instead of assigning it to variables you can just add the two charts together all the chart code so you can see i have mpg being piped into all and piped into filter piped into ggplot so basically this is all creating a chart but then at the end i have an additional plus that is adding it to the next ggplot chart so when we add this extra plus symbol it does the exact same thing as if we assigned it to variables and then structured that as you've seen in the prior examples so by doing this you could daisy chain all of these g plots together to achieve the same result without doing variable assignment and cluttering up your environment the only issue is that sometimes it might be hard to debug or find out where the issues are and that's a fair argument but you know different tools for different occasions so when i run this it will do exactly what we want left to right because it's a plus not a bit not a division so it's going to be plus so it has the exact same output as the earlier one just with no variable assignment so what happens when we add a bunch of these plots together if we add one two three four of these plots won't they just scrunch up and look really ugly going all the way from left to right well patchwork is a little bit smart with this so it will actually overflow into a grid square if it can so when we do this and we add four charts together it will produce a overflowed grid so it's doing a two by two grid of these two different charts so with that overflowed grid we can actually do a little bit of custom formatting by giving it an additional argument so we can add a plot layout function and with this we can say hey the number of rows we want is 3 and we're going to say by row false and doing this will give us the output of having three rows so that it will flow into each of these rows in the first option and then flow this way so by saying by row we're not overflowing left to right and then starting over in the next row we're doing we're going basically by column so the first column fills up and then the fourth chart goes to the top of the second column that's why we're doing three rows and saying by row is false so this way it's overflowing vertically top to bottom and we have three rows one and two columns so with this package you can actually get pretty complex with how you want to nest a lot of these things and in math we do the same sort of opera nesting operation with using parens so in this case you can see i have left and then a pipe the pipe is going to say hey this goes on the left and then everything else is going to be on the right so what is on the right that is currently in parens so a singular operation is going to occur first we're going to have top divided by bottom so that first example we saw is going to be completely on the right while another chart is on the left so when i run that code you can see we have one chart on the left and then the combination of top and bottom are on the right and this is done by using parens and if we just as an example gave this whole argument another set of parens and divided by right you can probably guess what's going to happen underneath this whole combination we now have the right chart so you can see how you could nest this and get some really complex layouts done with minimal syntax now with patchwork sometimes the plot titling and annotations and all that type of stuff can get a little bit complex but just as an example you can go look in the documentation for more about this type of stuff but just say you have this huge aggregated plot you have all these combinations in your layout and you have one giant visualization that is everything you want and you want to give it a title just the whole thing not individual charts to do that all you have to do is say hey here's all of my layout stuff add it to the function plot annotation where title equals you know whatever your title is so when we execute this right here at the top left here you go there is your plot annotation so i hope you find patchwork a very interesting package it's a very simple one very easy to pick up and i remember when it first started coming out and just our stats on twitter was just going crazy about it it's a very useful package for doing gg plot layouts without having to mess with ggplot layout code and doing any sort of weird combination very simple syntax very easy to use and honestly very useful one side note is if you use gg plotly to make interactive gg plots by tossing it into the plotly package that doesn't work well with patchwork and patchwork does not also work with lattice it's primarily made for gg plots as with all these package review videos you can find all of the code and documentation that i've used in my github repo for these package reviews and the link to that will be in the pinned comment below if you'd like to suggest video ideas talk hang out and just see what i'm working on you can join the discord in the link below and before i go a quick shout out to the patrons who support this channel thank you klaus alberto and devin thank you guys for supporting the channel and i'll catch you guys in the next one [Music] you
Original Description
▬▬▬▬▬▬▬▬▬▬ ► CHECK THESE OUT ◀︎▬▬▬▬▬▬▬▬▬▬
📧️ NEWSLETTER: https://bryanjenkstech.ck.page/d4ec0713d5
💬 DISCORD: https://discord.gg/MxCVshN
🗣️ SOCIALS: https://streamerlinks.com/tallguyjenks
▬▬▬▬▬▬▬▬▬▬ ► SUPPORT THE CHANNEL ◀︎▬▬▬▬▬▬▬▬▬▬
👨🏻💻️ GITHUB SPONSOR: https://github.com/sponsors/tallguyjenks
🙏🏻️ AMAZON WISHLIST: https://www.amazon.com/hz/wishlist/ls/17FRLE35NC7G8?ref_=wl_share
😇 PATREON: https://www.patreon.com/bryanjenks?fan_landing=true
🙌🏻️ YOUTUBE MEMBERSHIP: https://www.youtube.com/c/BryanJenksTech/join
☕ BUY ME A COFFEE: https://www.buymeacoffee.com/tallguyjenks
💵 PAYPAL: https://www.paypal.me/tallguyjenks
📊️ FREE STOCKS: http://join.robinhood.com/bryanj67
▬▬▬▬▬▬▬▬▬▬ ► My Newsletter ◀︎▬▬▬▬▬▬▬▬▬▬
📧️ NEWSLETTER: https://bryanjenkstech.ck.page/d4ec0713d5
▬▬▬▬▬▬▬▬▬▬ ► My Gear ◀︎▬▬▬▬▬▬▬▬▬▬
⚙️GEAR: https://kit.co/tallguyjenks/my-gear
▬▬▬▬▬▬▬▬▬▬ ► Questions? ◀︎▬▬▬▬▬▬▬▬▬▬
❓️FAQ: https://github.com/BryanJenksCommunity/FAQ/discussions
▬▬▬▬▬▬▬▬▬▬ ► Social ◀︎▬▬▬▬▬▬▬▬▬▬
💬 DISCORD: https://discord.gg/MxCVshN
🐦 TWITTER: https://twitter.com/tallguyjenks
📺 TWITCH: https://www.twitch.tv/tallguyjenks
📜️ MEDIUM: https://medium.com/@tallguyjenks
💼️ LINKEDIN: https://www.linkedin.com/in/bryanjenks/
🖥️ GITHUB: https://github.com/tallguyjenks
🌎 WEBSITE: https://www.bryanjenks.dev/
▬▬▬▬▬▬▬▬▬▬ ► The Rest ◀︎▬▬▬▬▬▬▬▬▬▬
Thanks for watching and if you liked this video please leave a 👍🏻
Subscribe to my channel and click the 🔔 icon for notifications when I post a new video
If you read this far put a 🐄 in the comments!
▬▬▬▬▬▬▬▬▬▬ ► TAGS ◀︎▬▬▬▬▬▬▬▬▬▬
#obsidian #zettelkasten #bryanjenks
Get The Code: https://github.com/tallguyjenks/RPackageReviews/tree/master/examples/patchwork
0:00:00 Welcome
0:00:26 Intro
0:01:43 Let Get Set Up
0:02:55 Preparing Your Plots For Patchwork
0:03:15 Top / Bottom Chart Layout
0:03:45 Side By Side Layout
0:04:10 Avoid Lots of Intermediary Variables, Just Combine Plots!
0:05:24 Overflow Grid Placement
0:05:48 Tweak Ov
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Bryan Jenks · Bryan Jenks · 47 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
▶
48
49
50
51
52
53
54
55
56
57
58
59
60
rsync for Linux Backups - The Final Barrier to Migration
Bryan Jenks
(un)Installing Packages From The (AUR) Arch Linux User Repository
Bryan Jenks
Full RStudio Set Up On Arch Linux
Bryan Jenks
Fix RMarkdown Compilation Outside Of RStudio on Arch Linux
Bryan Jenks
Markdown Document Autocompilation on Arch Linux
Bryan Jenks
Cronjobs, Cronie, & Crontab on Arch Linux
Bryan Jenks
Setting Up Slack With i3 on Arch Linux
Bryan Jenks
VS Codium (VS Code) on Arch Linux With A Shell Script
Bryan Jenks
Vimwiki Plugin For Vim Research Management on Arch Linux
Bryan Jenks
Neomutt with Protonmail on Arch Linux - LARBS - Thinkpad x220
Bryan Jenks
Command Line Task Management With Taskwarrior and Taskell On Arch Linux / Thinkpad x220
Bryan Jenks
Exploring My Fitbit Data With R in RStudio on Arch Linux
Bryan Jenks
Tellico Collections On Arch Linux
Bryan Jenks
LaTeX, Biber, and Live Compilation on Arch Linux
Bryan Jenks
R Markdown Programming Language Support
Bryan Jenks
R Markdown to make HTML Wiki's with Tabbed pages
Bryan Jenks
Announcement: New Video Series on R - "Comprehensive R Package Reviews"
Bryan Jenks
R Package Review Episode 1: Magrittr
Bryan Jenks
R Package Review Episode 2: Vitae
Bryan Jenks
My R Workflow for Reproduce-able & Portable Analysis
Bryan Jenks
R Package Review Episode 2: Here
Bryan Jenks
Introduction to Regular Expressions
Bryan Jenks
My Workflow for Reading, Organizing, and Maintaining Articles, Papers, & Books
Bryan Jenks
My First Python Project Dealing With Finance Data
Bryan Jenks
R Package Review Episode 4: Beepr
Bryan Jenks
RMarkdown Customized Styles with CSS and HTML Output
Bryan Jenks
RMarkdown Custom ID Selectors for Dynamic Headers and CSS
Bryan Jenks
HTML Headers in RMarkdown Documents For Personal/Corporate Branding
Bryan Jenks
My Semi-Complete VimWiki Workflow
Bryan Jenks
How To Make An Automated Resume With Github
Bryan Jenks
How I Use Fuzzy Finding In the Terminal with fzf (workflow++)
Bryan Jenks
How I Organize and Create My Research Notes (Research Workflow++)
Bryan Jenks
How I Use fzf.vim To Improve My Programming Workflow
Bryan Jenks
Website Updates, JavaScript, R, Shiny, Vue.js And More
Bryan Jenks
How To Use AWK (Tutorial)
Bryan Jenks
Bash Script Review: My Battery Power i3Blocks Module
Bryan Jenks
Channel Updates, Where I've Been, And Where I Want To Go With YouTube
Bryan Jenks
How To Use Neomutt 📨 From MuttWizard (Basics Tutorial)
Bryan Jenks
How To Use Jupyter Notebooks 📔 (Basics Tutorial)
Bryan Jenks
How To Use Trello In 2020 (The Definitive Guide)
Bryan Jenks
Macbook Pro 16 Inch 2020: Unboxing and Review
Bryan Jenks
How To Use Github's New Personal README and Wakatime
Bryan Jenks
How I Set Up My 2020 Macbook Pro 16
Bryan Jenks
My First Week At WGU (Western Governors University), Coffee, And Channel Updates
Bryan Jenks
The Best Academic Resources & Citation Managers: OrcID, Zotero, Mendeley & More!
Bryan Jenks
R Package Review Episode 5: TodoR
Bryan Jenks
R Package Review Episode 6: Patchwork
Bryan Jenks
Interview With Bryan of Norseman Leather Works
Bryan Jenks
Zettelkasten Work in Obsidian for Research | VOD
Bryan Jenks
How I Live With Adult ADHD (Attention Deficit Hyperactivity Disorder) [Time Stamped]
Bryan Jenks
Zettelkasten Research Work in Obsidian | VOD
Bryan Jenks
Obsidian VS Roam Research: Why I Chose Obsidian
Bryan Jenks
My 2020 Comprehensive Obsidian Workflow For Zettelkasten and Evergreen Notes
Bryan Jenks
How I Use Raindrop.io As The Entry Point of My Zettelkasten Workflow In Obsidian
Bryan Jenks
Comprehensive Overview | Obsidian Block References & Transclusion | Sorry Roam!
Bryan Jenks
Easy YouTube Timestamps From Final Cut Pro X With Python!
Bryan Jenks
NEW | Obsidian Insiders Release 0.9.10 | Plugins & Official API
Bryan Jenks
TOP 5️⃣️ | FAVORITE THINGS IN OBSIDIAN
Bryan Jenks
Comprehensive Obsidian & Git Sync Workflow 🔄️ | Your Mind Under Version Control
Bryan Jenks
Obsidian Mermaid Livestream Highlights | Zettelkasten Resources, YouTube Advice, Data Science
Bryan Jenks
Related Reads
📰
📰
📰
📰
10 Ways Small Businesses Can Use AI To Grow–And Even Hire More Workers
Forbes Innovation
Beyond Connectivity: How Wi-Fi Is Becoming One of the World’s Largest Passive Sensor Networks
Medium · AI
Automating Form I-130 Drafting – Spouse, Parent, Spouse, Parent, Sibling, and Child Petitions Made Simple
Dev.to AI
Every digital creator, developer, and marketer knows the silent frustration of the modern workflow…
Medium · AI
Chapters (9)
Welcome
0:26
Intro
1:43
Let Get Set Up
2:55
Preparing Your Plots For Patchwork
3:15
Top / Bottom Chart Layout
3:45
Side By Side Layout
4:10
Avoid Lots of Intermediary Variables, Just Combine Plots!
5:24
Overflow Grid Placement
5:48
Tweak Ov
🎓
Tutor Explanation
DeepCamp AI