On May 10, 2012, at 8:07 AM, John Kane wrote:
I don't think there is any other way.
There is:
a <- c(10, 20, 30, 40)
b <- c(50, 250, 500, 600)
ba <- b/a
par(las=1, mar=c(5,5,.5,5))
plot(a,b, type="b", pch=22, cex=2, col=4, lwd=2, ylim=c(0,650),
xlim=c(0,45))
par(new=TRUE)
plot(a,ba,type="b", pch=21, cex=2, col=2, lwd=2, lty=1, xlim=c(0,45),
yaxt="n")
axis(4, at=c(seq(0,25,length=6)), lab=c(seq(0,25,length=6)),
col.axis=2 )
# could also specify ylim of c(0,25) to the second plot call.
# probably want to have ylab="" in one or both of those plot calls, too.
But I do agree this can be considered deceptive plotting practice.
--
David.
On the other hand, most gurus suggest that a dual scales on a graph
are not a good thing.
What about using a two panel graph?
Quick rejigging of your code :
=================================================================
a <- c(10, 20, 30, 40)
b <- c(50, 250, 500, 600)
ba <- b/a
op <- par(las=1, mar=c(5,5,.5,5), mfrow=c(2, 1))
plot(a,b, type="b", pch=22, cex=2, col=4, lwd=2, ylim=c(0,650),
xlim=c(0,45))
plot (a,ba, type="b", pch=21, cex=2, col=2, lwd=2, lty=1)
par(op)
==================================================================
John Kane
Kingston ON Canada
-----Original Message-----
From: pann...@gwdg.de
Sent: Thu, 10 May 2012 04:37:37 -0700 (PDT)
To: r-help@r-project.org
Subject: [R] additional axis, different scale
Dear list,
I am looking for a possibility to present results in a more
graphical way
by
adding an axis. But I have trouble relating my data to the added
axis.
Imagine the following example:
a <- c(10, 20, 30, 40)
b <- c(50, 250, 500, 600)
ba <- b/a
par(las=1, mar=c(5,5,.5,5))
plot(a,b, type="b", pch=22, cex=2, col=4, lwd=2, ylim=c(0,650),
xlim=c(0,45))
axis(4, at=c(seq(0,600,length=6)), lab=c(seq(0,25,length=6)),
col.axis=2 )
lines(a,ba, type="b", pch=21, cex=2, col=2, lwd=2, lty=1)
I want the red line to relate its values to the x-axis (a) and axis
4 (on
the right) and not as usual to the x-axis (a) and the y-axis (b).
This would show the tendency of the red line much clearer which now
can't
be
seen because of the very different scaling.
E.g. I want R to know that I am trying to plot the first point of
the red
line P1(50/5) using the x-axis and the right axis, not the y-axis
on the
left ect.
I would like to solve this without using a factor solution like:
bb <-600/25 * ba
lines(a,bb, type="b", pch=21, cex=2, col=3, lwd=2, lty=1)
For any kind of help I would be grateful !
--
View this message in context:
http://r.789695.n4.nabble.com/additional-axis-different-scale-tp4623210.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at
http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google
Talk™ and most webmails
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.