Two y axes with identical text

1,022 views
Skip to first unread message

Sam Albers

unread,
Nov 7, 2016, 4:28:23 PM11/7/16
to ggplot2
Hi all,

First of all this isn't a two y axes with difference scales question. :)

But what I am interested in finding is if there any way, in ggplot2,
to plot a second identical y axis (labels and all) on the right hand
side of the plot?

So in this example, I would like to simply add the Ozone.R axis on the
right hand side of the plot.

ggplot(airquality,aes(x=Ozone,y=Solar.R)) +
geom_point()

Thanks in advance,

Sam

Brandon Hurr

unread,
Nov 7, 2016, 4:58:37 PM11/7/16
to Sam Albers, ggplot2
Sam, 

I think this can be done using some very new things that Thomas Pedersen mixed into ggplot2, but I'm not sure how far he got on this before finishing his internship with Hadley. 


What I'm thinking is you could use this hack to faceting but set the transformation to 1 and give it the same label as the left-hand side of the plot. 

I've reached out to them on twitter to see if there is something there, but it's late in Denmark... 

Brandon


--
--
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+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 email to ggplot2+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brandon Hurr

unread,
Nov 7, 2016, 5:09:39 PM11/7/16
to Sam Albers, ggplot2
Alright, if you have the dev version of ggplot2 or can wait a few days for this to propagate to the CRAN binary you can do this quite easily thanks to Thomas. 
ggplot(mtcars, aes(cyl, mpg)) +
geom_point() +
scale_y_continuous(sec.axis = dup_axis())

?sec_axis #for more information

Brandon

Sam Albers

unread,
Nov 15, 2016, 12:34:30 PM11/15/16
to Brandon Hurr, ggplot2
Hi all,

Great changes with the newest ggplot2! Following up on this request I
see that the duplicate axis is only built for continuous variable:

library(ggplot2)
library(dplyr)

iris %>%
ggplot(aes(x=Petal.Width, y=Species)) +
geom_point() +
scale_y_discrete(sec.axis = dup_axis())


iris %>%
ggplot(aes(x=Petal.Width, y=Species)) +
geom_point() +
scale_x_continuous(sec.axis = dup_axis())

So I am back to square one here. Does anyone know how to duplicate a
discrete axis like sec_axis but using a discrete variable?

Sam

P.S. Facetting really is quite improved with this version. Amazing stuff.
>>> 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.
Reply all
Reply to author
Forward
0 new messages