1

EDIT: I've read through this question but that does not(in my opinion) readily solve the problem. Also considering, it's a bit old; perhaps someone has come up with a hack that does not need one to do more "hacking".

Given some dummy data below:

dummy_df<-data.frame(A=runif(50,0,5),B=runif(50,5,90),Group=c(1,2))
dummy_df %>% 
  ggplot(aes(A,B))+geom_point()+
  facet_grid(.~Group)+
  coord_cartesian(xlim=c(1,3))

Current plot: enter image description here

How could one apply the last call to only a single facet say only facet 1 of this plot?! I would name it something like zoom_at(facet_1). Thanks in advance.

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
  • Possible duplicate of [R: How do I use coord\_cartesian on facet\_grid with free-ranging axis](https://stackoverflow.com/questions/12207419/r-how-do-i-use-coord-cartesian-on-facet-grid-with-free-ranging-axis) – A. Stam Apr 05 '19 at 12:16
  • why not just filter dummy_df to inlcude only one group before calling ggplot? – adibender Apr 05 '19 at 12:19
  • @adibender That's an option. However, this came into my head as I was trying to make some plots. I thought it would be great to find a way to do it. – NelsonGon Apr 05 '19 at 12:20
  • 1
    You can also check out the package `gridExtra`. I am not very familiar with it, but It could have some functionalities to tackle your problem – Sotos Apr 05 '19 at 12:23
  • 1
    You might try `patchwork` or `cowplot` to make the plots separately with the limits you want, then stick them together. You can style them to look more or less the same as facets but with your specified limits – camille Apr 05 '19 at 14:15

1 Answers1

1

maybe not exactly what you are looking for but it might open up another way how to approach it

library(ggforce)
library(tidyverse)
dummy_df<-data.frame(A=runif(50,0,5),B=runif(50,5,90),Group=c(1,2))

dummy_df %>% 
  ggplot(aes(A,B))+geom_point(aes(color=as.factor(Group)))+
  facet_zoom(zoom.data = Group =='2', xlim=c(1,3))
adibender
  • 7,288
  • 3
  • 37
  • 41
zoowalk
  • 2,018
  • 20
  • 33