Home > Mobile >  Facet, plot axis on all outsides
Facet, plot axis on all outsides

Time:06-07

Is there a way to mirror the x-/y-axis to the opposite side (only outside, no axis on the inside)? My goal is to get something like:

enter image description here


MWE

library(ggplot2)

ggplot(data = iris, aes(x=Sepal.Length, y=Sepal.Width))  
  geom_point()  
  facet_grid(rows = "Species")

CodePudding user response:

This should work:

ggplot(data = iris, aes(x=Sepal.Length, y=Sepal.Width))  
  geom_point()  
  scale_y_continuous(sec.axis = sec_axis(~.*1)) 
  scale_x_continuous(sec.axis = sec_axis(~.*1)) 
  facet_grid(rows = "Species")

enter image description here

CodePudding user response:

Yes, you can use the guides() function to set axes for secondary positions as well, see example below. To have it more like your example, the strip placement should be changed to "outside".

library(ggplot2)

ggplot(iris, aes(Sepal.Length, Sepal.Width))  
  geom_point()  
  facet_grid(rows = vars(Species))  
  guides(
    x.sec = "axis", y.sec = "axis"
  )  
  theme(strip.placement = "outside")

Created on 2022-06-07 by the reprex package (v2.0.0)

  • Related