Multiple rug plots on the same side of the plot margin

Hi,

Does anyone know if it is possible to have multiple rug plots on the same outside margin of a plot?

For example, I have two rugs on the plot below, colored by different discrete variables, but I would like them both on the right-hand side, but non-overlapping. One of them further outside of the other rug (i.e. stacked rugs).

library(tidyverse)
library(palmerpenguins)

penguins %>% 
  ggplot(aes(bill_length_mm, bill_depth_mm)) +
  geom_point() +
  geom_rug(aes(color = species), sides = 'r') +
  geom_rug(aes(color = sex), sides = 'l') +
  theme_minimal(14)
#> Warning: Removed 2 rows containing missing values (geom_point).

Putting one outside and one inside works, but this limits you to two rugs. Hope to have an approach that is extensible to an arbitrary number of rugs on the outer margin.

library(tidyverse)
library(palmerpenguins)

penguins %>% 
  ggplot(aes(bill_length_mm, bill_depth_mm)) +
  geom_point() +
  geom_rug(aes(color = species), sides = 'r', outside = F) +
  geom_rug(aes(color = sex), sides = 'r', outside = T) +
  coord_cartesian(clip = 'off') +
  theme_minimal(14) +
  theme(
    plot.margin = unit(c(0,1,0,0), 'in'),
    legend.position = 'bottom'
  )
#> Warning: Removed 2 rows containing missing values (geom_point).

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.