library(ggplot2)
library(tibble)
data(mtcars)
my_mtcars <- mtcars %>%
tibble::rownames_to_column(var = "car") %>%
dplyr::select(car,mpg,wt, gear)
p1 <- ggplot2::ggplot(my_mtcars, ggplot2::aes(x = mpg, y = car )) +
ggplot2::geom_point()
p2 <- p1 + ggplot2::facet_grid(gear ~ . , scales = "free", space = "free", switch = "y")
Issue: In p2, “car” (y-axis) variable is re-arranged according to “gear” order (e.g. 3,4,5). But in p2, I want to keep the order of “car” (y-axix) same as in p1, which means ignoring the order of “gear”.
I will be thankful for any suggestion.