简体   繁体   中英

How to flip a ggplot horizontally?

I have a ggplot spaghetti plot that currently looks like this:

当前的ggplot

I'd like to flip it on the x-axis (horizontally) so that it looks like this:

想要的ggplot

But I cannot figure out how... coord_flip gives me this plot:

不需要的ggplot

which is not what I'm looking for.

how can I go about doing this?

I used my own data to simulate what you wanted. You should just need the last two lines of code.

library(ggplot2)
library(tidyverse)

set.seed(55)
scatter_data <- tibble(x_var = runif(100, min = 0, max = 25)
             ,y_var = log2(x_var) + rnorm(100)
             )

p <- ggplot(data = scatter_data, aes(x = x_var, y = y_var)) +
  geom_point()

p + scale_x_reverse(lim =c(25,0)) +
 scale_y_continuous(position = "right")

翻转情节

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM