New Version of Patchwork is Here: Inset a plot inside a plot

Deployment of patchwork

The new version of the R Patchwork package is available from CRAN. If you’re not familiar with patchwork, here’s the R-package developed by the same Thomas Lin Pedersen, which allows you to combine multiple stories created with R into a single diagram using ggplot2 or Basic-R.

As Thomas Lin Pederson says, the patchwork quilt…

Allows you to easily link graphics, mainly based on ggplot2, but with support for basic graphics.

As a fan of Patchwork, I was very happy to see one of its new features. The new version has the possibility to insert itself into the plot. In version 1.1.0.9000 of the patchwork there is a new function inset_element() which allows you to specify the exact position of the input borders in each grid unit, giving you complete freedom to place the area in the cross section.

Let’s see how we can make a patchwork blanket. Let’s start by loading the right packages, here carefully and unevenly.

Library(neat)
Library(patchwork)
topic_set(theme_bw(16))

Make sure we have the correct version of the patchwork package.

Patchwork version

We will use mobile and fixed phone records that contain data on the growth of users over time around the world, starting with the TidyTuesday project.

mobile <- readr::read_csv(‘https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-11-10/mobile.csv’)

## Disassembled with speaker specifications:## cols(## entity = col_character(),## code = col_character(),## code = col_double(),## year = col_double(),## total_pop = col_double(),## gdp_per_cap = col_double(),## mobile_subs = col_double(),## continent = col_character()## ).

To achieve the same simplicity, we look at data that only matches the United States. Let’s make a mobile subscription bar plot for the United States in time.

p1 <- mobile %>%
filter(entity==United States) %>%
ggplot(aes(x=year, y=mobile_subs)) +
geom_col()+
labs(title=Mobile subscriber usage: United States)
print(p1)

We clearly see the growth in the number of mobile phone subscriptions over time.

Growth of mobile communications in the United States

Growth of mobile communications in the United States

It’s time to look at lowering the fixed rates. First we download data from a landline directly from the github side.

fixed line <- readr::read_csv(‘https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-11-10/landline.csv’)

## disassembled with speaker specifications:## cols(## entity = col_character(),## code = col_character(),## code = col_double(),## year = col_double(),## total_pop = col_double(),## gdp_per_cap = col_double(),## landline_subs = col_double(),## continent = col_character()## )

We do the same bar chart with life dates.

p2 <- Fixed network %>%
filter(entity==United States) %>%
ggplot(aes(x=year, y=fixed network_subs)) +
geom_col()+
labs(title=fixed network subscriber growth: United States)
print(p2)

The growth of the number of fixed lines in the United States

The growth of fixed telephony in the United States

We saved both graphs as variables and are ready to use the patch inserts. The patch contains the function inset_element(), which makes it possible to add an insert to an existing section. Here we add a fixed part to the mobile part.

p1 + insert_element(p2, right = 0,5,
down = 0,4,
left = 0,01,
up = 0,96)
ggsave(insert_with_patchwork.png, width=9,height=8)

With the inset_element() function of Patchwork you can determine an exact position to place the second segment in the first one. Here we adjust the position and size of the insert with the arguments right, bottom, left and top.

Inserting parts of the patch code in R

Inserting parts of the patch code in R

Although the possibility of having an insole is fantastic, the correct use of the insole can be difficult. For example, think about where the supplement is most suitable instead of talking about facets. One possible application is if you have a basic conspiracy that you want to draw attention to, but another related conspiracy that may emphasize the importance of the basic hole is a scenario in which an addition may be useful.

1.Access the settings menu of your device Posh Orion Max X550, this is the cogwheel icon.2.Scroll down the Posh Orion Max X550 settings to the bottom where you will see the section called "System", click to continue.3.If you see a section called "Advanced" click to display the advanced options of the Posh Orion Max X550.,1.Access the settings menu of your device Posh Orion Max X550, this is the cogwheel icon.,2.Scroll down the Posh Orion Max X550 settings to the bottom where you will see the section called "System", click to continue.,3.If you see a section called "Advanced" click to display the advanced options of the Posh Orion Max X550.

You May Also Like