Examples for 'patchwork::inset_element'


Create an inset to be added on top of the previous plot

Aliases: inset_element

Keywords:

### ** Examples

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)
plot of chunk example-patchwork-inset_element-1
# Align to the full area instead
p1 + inset_element(p2, 0, 0.6, 0.4, 1, align_to = 'full')
plot of chunk example-patchwork-inset_element-1
# Grobs and other objects can be added as insets as well
p1 + inset_element(grid::circleGrob(), 0.4, 0.4, 0.6, 0.6)
plot of chunk example-patchwork-inset_element-1
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')
plot of chunk example-patchwork-inset_element-1
# Just as expected insets are still amenable to changes after the fact
p1 +
  inset_element(p2, 0.6, 0.6, 1, 1) +
  theme_classic()
plot of chunk example-patchwork-inset_element-1
# Tagging also continues to work as expected
p1 +
  inset_element(p2, 0.6, 0.6, 1, 1) +
  plot_annotation(tag_levels = '1')
plot of chunk example-patchwork-inset_element-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')
plot of chunk example-patchwork-inset_element-1

[Package patchwork version 1.1.1 Index]