Inverting Y axis

41 views
Skip to first unread message

Pablo Bernabeu

unread,
Oct 24, 2016, 12:49:33 PM10/24/16
to ggplot2
Hi all,

I've been trying to find out how to invert the Y axis but to no avail. I would really appreciate any of your help. Please find the code below.

Best regards
_______________________________________________

plot = ggplot(data, aes(x=X, y=Y, color=Z)) + 
  geom_line(size=1, alpha = 1)+
  scale_linetype_manual(values=c(1,1))+
  scale_y_continuous(limits=c(-7, 7), breaks=seq(-7,7,by=1))+ 
  scale_x_continuous(limits=c(-200,800),breaks=seq(-200,800,by=100), 
  labels=c("-200","-100","0","100","200","300","400","500","600","700","800"))+
  ggtitle("title")+
  ylab("Amplitude")+
  xlab("Time")+
  theme_bw() +
  geom_vline(xintercept=0) +
  geom_hline(yintercept=0)

Zack Weinberg

unread,
Oct 24, 2016, 3:19:19 PM10/24/16
to Pablo Bernabeu, ggplot2
Does scale_y_reverse() do what you want? If it doesn't, please show
us the plot you get and tell us what about it is wrong. It would also
help if we could see some example data.
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Pablo Bernabeu

unread,
Oct 24, 2016, 3:32:07 PM10/24/16
to Zack Weinberg, ggplot2
Thank you, Zack. As it turned, I just received a reply on CrossValidated that worked well. This solution was inverting the polarity of Y in the mapping, aes(y = -Y), and then adding , labels = rev within scale_y_continuous()

I had tried scale_y_reverse() earlier but it didn't work.

Best regards

> To unsubscribe: email ggplot2+unsubscribe@googlegroups.com

> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
Reply all
Reply to author
Forward
0 new messages