y-axis on the right side

3,498 views
Skip to first unread message

Luciano Selzer

unread,
Sep 21, 2010, 9:36:30 AM9/21/10
to ggplot2
Hi group, on a quick search I haven't been able to found an answer to this. Is it possible to switch the y-axis side? I would like it to be on the right rather than the left. Just to make it clear I don't want a second y-axis.

Thanks in advance
Luciano

Hadley Wickham

unread,
Sep 21, 2010, 8:13:36 PM9/21/10
to Luciano Selzer, ggplot2
Not at the moment, but it's on my long delayed to do list :/
Hadley

> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Rob James

unread,
Sep 21, 2010, 8:27:26 PM9/21/10
to ggp...@googlegroups.com
Without endorsing the idea at all, or having tested it... and only if
one was absolutely desperate.... but I suspect that you leave the y
axis stationary, flip everything else -- axis text labels rotated
180', scales reversed etc. so that while the legend was still
technically "on the left" the image could not be readily readable after
one rotated the image through 180'. This would make the left axis
appear to be "on the right". I haven't tried it yet... it would require
a very good reason, ... but I think the flexibility might already be there.

Good luck!

Brandon Hurr

unread,
Sep 22, 2010, 3:47:32 AM9/22/10
to Rob James, ggp...@googlegroups.com
I can't figure out how to rotate the axis label, but otherwise your
method seems solid. You just rotate the picture afterwards.

df<-as.data.frame(cbind(x=1:10, y=1:10))

ggplot(df, aes(x=x, y=y))+
geom_point()+
geom_line()+
scale_x_continuous('upsidedown?', trans='reverse')+
scale_y_continuous('correcto?')+
opts(axis.text.x=theme_text(angle=180, hjust=0.5, vjust=-0.25),
axis.text.y=theme_text(angle=180, hjust=0, vjust=0.5),

#doesn't work, and I don't know the right call
axis.label.x=theme_text(angle=180, hjust=0, vjust=0)
)

#Brandon

On Wed, Sep 22, 2010 at 01:27, Rob James <r...@aetiologic.ca> wrote:
>
> Without endorsing the idea at all, or having tested it...  and only if one was absolutely desperate....  but I suspect that you leave the y axis stationary,  flip everything else -- axis text labels rotated 180',  scales reversed etc. so that while the legend was still technically "on the left" the image could not be readily readable after one  rotated the image through 180'. This would make the left axis appear to be "on the right".  I haven't tried it yet... it would require a very good reason, ... but I think the flexibility might already be there.
>
> Good luck!
>
>
>

test.png

Brandon Hurr

unread,
Sep 22, 2010, 4:24:43 AM9/22/10
to Rob James, ggp...@googlegroups.com
Just figured it out...


ggplot(df, aes(x=x, y=y))+
geom_point()+
geom_line()+
scale_x_continuous('Right-side Up', trans='reverse')+
scale_y_continuous('good enough?')+

opts(axis.text.x=theme_text(angle=180, hjust=0.5, vjust=-0.25),
axis.text.y=theme_text(angle=180, hjust=0, vjust=0.5),
axis.title.x=theme_text(angle=180)
)

Really could use an opts() list, I figured it out by noticing that you could adjust the plot.title and assumed that the naming convention was retained for the axis.title. Makes sense now, but I just blew 20 minutes googling trying to find something that should have been easily found on the wiki. /rant
better.png

Scott Chamberlain

unread,
Jan 9, 2012, 12:42:14 PM1/9/12
to ggp...@googlegroups.com
Apologies for resurrecting this old thread. 

Brandon, this code doesn't seem to work for me.  I get the error: 

> df<-as.data.frame(cbind(x=1:10, y=1:10))
> ggplot(df, aes(x=x, y=y))+
+   geom_point()+
+   geom_line()+
+   scale_x_continuous(trans='reverse')+
+   scale_y_continuous('good enough?')+
+   
+   opts(
+     axis.text.x=theme_text(angle=180, hjust=0.5, vjust=-0.25), 
+     axis.text.y=theme_text(angle=180, hjust=0, vjust=0.5), 
+     axis.title.x=theme_text(angle=180)
+        )
Error: Zero breaks in scale for x/xmin/xmax/xend/xintercept

Any thoughts as to why it dosen't work?

Thanks! Scott

seancarmody

unread,
Nov 5, 2013, 5:38:53 AM11/5/13
to ggp...@googlegroups.com, Luciano Selzer, had...@rice.edu
Just wondering whether there is any chance that this feature has been bumped up the todo list.

Like Luciano, I am not interested in (justly maligned) secondary axes, rather the ability to have the y-axis on the right hand side instead of the left. When plotting timeseries in particular, it is common for readers to be more interested in quickly gauging the more recent values of in the data series rather than the oldest values.

Regards,
Sean.

baptiste auguie

unread,
Nov 5, 2013, 7:20:45 AM11/5/13
to seancarmody, ggplot2


--
--
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/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages