Technique for multiple x axis merely for user viewing

79 views
Skip to first unread message

ch...@chrismitchellhome.net

unread,
May 11, 2010, 1:49:34 PM5/11/10
to ggp...@googlegroups.com
Let's se we had data like this
 
d <- data.frame(tempcelcius=rnorm(25,15, 10),attendence=rnorm(25,500, 100))
qplot(x=tempcelcius,y=attendence,data=d)
 
Is it possible to add a scaled second axis that is in degrees farenheight so that the user could read the axis in degC or degF?  Another possibility I envision (and have a use for) is a datetime/axis with different time zones.
 
Thanks,

--
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

Andrie de Vries

unread,
May 13, 2010, 3:45:14 PM5/13/10
to ggplot2
Chris

Quoting from the ggplot2 book, page 166: "There is no way to produce
a plot with two axes in ggplot2 because this type of plot is
fundamentally misleading".

What you want to do is slightly different though, so here is one
workaround. The idea is to modify the scale labels to display
temperaturs in Celsius as well as Fahrenheit:

degC <- seq(0,100,10)
degCandF <- paste(degC,"C / ",degC * 9 / 5 + 32,"F",sep="")

d <- data.frame(tempcelcius=round(rnorm(25,15, 10),
1),attendence=rnorm(25,500, 100))


p <- qplot(x=tempcelcius,y=attendence,data=d)
p <- p + scale_x_continuous("Temperature (Celsius/
Fahrenheit)",breaks=degC,labels=degCandF)
print(p)

--

Andrie

Hadley Wickham

unread,
May 16, 2010, 1:19:26 PM5/16/10
to Andrie de Vries, ggplot2
> Quoting from the ggplot2 book, page 166:  "There is no way to produce
> a plot with two axes in ggplot2 because this type of plot is
> fundamentally misleading".

That should really say two *scales*. Two axes are ok if they are
transformations of one another. Laying the ground work for a
secondary transformed axis is on my to do list for this summer.

Hadley

ch...@chrismitchellhome.net

unread,
May 16, 2010, 5:57:30 PM5/16/10
to Hadley Wickham, Andrie de Vries, ggplot2
Thank you Andrie and Hadley..



________________________________________
From: ggp...@googlegroups.com [ggp...@googlegroups.com] on behalf of Hadley Wickham [had...@rice.edu]
Sent: Sunday, May 16, 2010 10:19 AM
To: Andrie de Vries
Cc: ggplot2
Subject: Re: Technique for multiple x axis merely for user viewing
Reply all
Reply to author
Forward
0 new messages