Re: [R] How to invert axis within defined range with ggplot2 scale_y_reverse?
Thank you. I though the values would have been reversed automatically. Case closed then On Tue, Mar 5, 2024 at 2:43 PM Duncan Murdoch wrote: > > On 05/03/2024 7:16 a.m., Luigi Marongiu wrote: > > A <- rep(c(0, 3, 6, 12, 24), 3) > > B <- c(rep(0,5), rep(1,5), rep(2,5)) > > V <- c(27.5,27.01,27.75,27.98,27.4,25.69, > > 26.17,27.78,26.08, > > 24.97,23.18,21.78,22.49,21.85,22.2) > > df <- data.frame(Conc = A, Time = B, Value = V) > > df$Conc = as.factor(df$Conc) > > df$Time = as.factor(df$Time) > > library(ggplot2) > > > > ggplot(df, aes(x=Time, y=Value, colour=Conc, group=Conc)) + > >geom_line() + > >scale_y_reverse(limits = c(20,30)) + > >geom_point(size=6) + > >scale_colour_manual(values = COLS) > > The limits should be `c(30,20)`. > > Duncan Murdoch -- Best regards, Luigi __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to invert axis within defined range with ggplot2 scale_y_reverse?
On 05/03/2024 7:16 a.m., Luigi Marongiu wrote: A <- rep(c(0, 3, 6, 12, 24), 3) B <- c(rep(0,5), rep(1,5), rep(2,5)) V <- c(27.5,27.01,27.75,27.98,27.4,25.69, 26.17,27.78,26.08, 24.97,23.18,21.78,22.49,21.85,22.2) df <- data.frame(Conc = A, Time = B, Value = V) df$Conc = as.factor(df$Conc) df$Time = as.factor(df$Time) library(ggplot2) ggplot(df, aes(x=Time, y=Value, colour=Conc, group=Conc)) + geom_line() + scale_y_reverse(limits = c(20,30)) + geom_point(size=6) + scale_colour_manual(values = COLS) The limits should be `c(30,20)`. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to invert axis within defined range with ggplot2 scale_y_reverse?
Hello, I am drawing some data with ggplot2 and would like to reverse the order of the y axis and set a custom range for it. I can do the former but when I add the key `limits` to `scale_y_reverse` I get an error as shows below and, worse, no data shown in the plot. How can I properly set a reverse y scale with a defined range in ggplot2? Thank you ``` A <- rep(c(0, 3, 6, 12, 24), 3) B <- c(rep(0,5), rep(1,5), rep(2,5)) V <- c(27.5,27.01,27.75,27.98,27.4,25.69, 26.17,27.78,26.08, 24.97,23.18,21.78,22.49,21.85,22.2) df <- data.frame(Conc = A, Time = B, Value = V) df$Conc = as.factor(df$Conc) df$Time = as.factor(df$Time) library(ggplot2) ggplot(df, aes(x=Time, y=Value, colour=Conc, group=Conc)) + geom_line() + scale_y_reverse(limits = c(20,30)) + geom_point(size=6) + scale_colour_manual(values = COLS) > Warning messages: 1: Removed 15 rows containing missing values (`geom_line()`). 2: Removed 15 rows containing missing values (`geom_point()`). ``` __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.