7

I am trying to zoom into multiple sections within a plot.

I know that with facet_zoom I can zoom into a section of the plot. For example:

ggplot(iris, aes(Petal.Length, Petal.Width, colour = Species)) +
  geom_point() +
  facet_zoom(x = Species == "versicolor")

facet_zoom on 1 area

I would however like to zoom into more then 1 area within the same plot. Is this possible?

I tried:

ggplot(iris, aes(Petal.Length, Petal.Width, colour = Species)) +
  geom_point() +
  facet_zoom(x = Species == "setosa"|Species == "virginica")

but this doesn't work because selection includes the whole range.

enter image description here

In this simple example I would ideally have two zoomed plots below each other for the two different species.

Das_Geek
  • 2,775
  • 7
  • 20
  • 26
user572549
  • 71
  • 4

1 Answers1

0

I don't know what specific, you are looking for, but facet_zoom also comes with limit arguments, like xlim, ylim, that you can adjust to zoom in specific regions. like: (this image is zoomed from 2 - 4 on x-axis)

iris %>% ggplot(aes(Petal.Length, Petal.Width, color = Species)) +
  geom_point()+ theme_bw() +
  facet_zoom(xlim = c(2,4))

enter image description here

Saurav Das
  • 104
  • 2