Instead of double y-axis

757 views
Skip to first unread message

thomas

unread,
Aug 6, 2009, 1:27:00 PM8/6/09
to ggplot2
Hello,

As it appears that there is no way to plot 2 y-axis in ggplot, I would
be interested in your viewpoint about the best way to plot these data:

I am surveying mortality during experiments where I change gradually a
parameter (the temperature).
Before using ggplot2 (really great any way ;) I was plotting the
number of individuals against time, and added a second y-axis to plot
temperature against time.

I thought about (i) adding text labels, which is not really satisfying
since I would like to be able to read precisely temperature between
two labels; (ii) adding a color rectangle with a gradient in the
background, but it is not so straight forward and does not give access
to precise temperature data; (iii) superimposing two plots one for the
temperature, the other for the number of individuals.

Is there a another (better) option? concerning the faceting with
different axis, what is the best option? is there a lighter way than
viewports?

Thank you in advance,

Thomas

mroessler

unread,
Aug 6, 2009, 4:39:26 PM8/6/09
to ggplot2
My understanding of Hadley's opinion regarding two y-axes and his
intention with ggplot2, based on a read of his book, is to
purposefully omit double y-axes in favor of using one of two options:
1) rebase your series so that they fit onto a common y-axis, or 2) use
facet_grid to create two charts (one above the other, for example) to
show comparative movement on independent y-axes. If you use the second
option, consider setting scale="free-y" or even scale="free" as
appropriate.

I hope this helps you.

Michael

Peter Flom

unread,
Aug 7, 2009, 5:17:37 AM8/7/09
to mroessler, ggplot2
William Cleveland and Howard Wainer have both written about how dangerous double-y axis graphs are.
Essentially, you can make them say anything you want by changing the scales of the axes relative to each
other.

Peter
Peter L. Flom, PhD
Statistical Consultant
www DOT peterflomconsulting DOT com
http://www.associatedcontent.com/user/582880/peter_flom.html

smu

unread,
Aug 7, 2009, 5:25:43 AM8/7/09
to ggplot2
On Fri, Aug 07, 2009 at 05:17:37AM -0400, Peter Flom wrote:
>
> William Cleveland and Howard Wainer have both written about how dangerous double-y axis graphs are.
> Essentially, you can make them say anything you want by changing the scales of the axes relative to each
> other.

But this is also possible with facet_grid. So why are facets less
dangerous than double-y axis?

I think, in many situations facets are clearer, but sometimes I would
also prefer double-y axis.


Stefan

thomas

unread,
Aug 7, 2009, 9:31:49 AM8/7/09
to ggplot2
Thank you for all your answers…

I manage to do this using viewport already, will try with scale="free-
y" asap…
I definitely agree with Stephan: in this very example, I have two
physical method to estimate the number of individuals (in two
different units). It would be much more convenient to have double axis
instead of facets.

Regards,

Thomas


thomas

unread,
Aug 7, 2009, 9:33:54 AM8/7/09
to ggplot2
Actually scales="free" does not do the job: in my case, I wan't to
plot two different variable on y-axis…
Any clue?…

Mike Lawrence

unread,
Aug 7, 2009, 11:14:22 PM8/7/09
to thomas, ggplot2
Simple example data always help when requesting aid on this list...

a = expand.grid(DV=c('Temperature\n(degrees Celsius)','Deaths
per\nthousand'),x=1:10)
a$y = NA
a$y[a$DV=='Temperature\n(degrees Celsius)'] = rnorm(10,20,10)
a$y[a$DV=='Deaths per\nthousand'] = rnorm(10,5,1)

Now, does this suffice?

ggplot(a,aes(x=x,y=y))+facet_grid(DV~.,scales='free_y')+ylab('')+geom_point()+geom_line()
--
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tr.im/mikes_public_calendar

~ Certainty is folly... I think. ~

Peter Flom

unread,
Aug 7, 2009, 5:28:17 AM8/7/09
to smu, ggplot2
>
>On Fri, Aug 07, 2009 at 05:17:37AM -0400, Peter Flom wrote:
>>
>> William Cleveland and Howard Wainer have both written about how dangerous double-y axis graphs are.
>> Essentially, you can make them say anything you want by changing the scales of the axes relative to each
>> other.
>

Stefan replied

>But this is also possible with facet_grid. So why are facets less
>dangerous than double-y axis?
>
>I think, in many situations facets are clearer, but sometimes I would
>also prefer double-y axis.
>
>

facet_grid, at least by default, uses the same y-axis throughout the facets.

Peter

Reply all
Reply to author
Forward
0 new messages