Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch right-hand strip to left side in facet_grid

I have the following code:

library(tidyverse)
p <- ggplot(mpg, aes(displ, cty)) + geom_point()
p + facet_grid(drv ~ .)

Which produces this plot:

enter image description here

As describe above how can I switch right-hand strip to left side and vice versa.

like image 842
scamander Avatar asked Sep 06 '25 06:09

scamander


1 Answers

You could use switch in facet_grid to change the facet strip to left and scale_y_continuous to change y-axis to right.

library(ggplot2)

p + facet_grid(drv ~ ., switch = "y") + 
   scale_y_continuous(position = "right")

enter image description here

like image 178
Ronak Shah Avatar answered Sep 07 '25 21:09

Ronak Shah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!