Hi Andy,
this is my way of doing it:
#first data:
wetMeans<-c(9.904762,6.344828,6.346154,6.855769,9.074324,9.953988,13.482966,
14.546053,10.841584,9.752033,6.739336,8.955056)
burnMeans<-c(0.06214286,0.05396552,0.04096154,0.05302885,0.05831081,0.073926
38,0.29969940,0.25596217,0.09316832,0.14441057,0.13180095,0)#0.05348315)
#your code
library(plotrix)
par(oma=c(1,1,1,1))
par(las=1)
xvals <- barp(wetMeans, xlab="", ylab="",
main="TEST", col="grey",
names.arg=c("Jan","Feb","Mar","Apr","May",
"Jun","Jul","Aug","Sep","Oct","Nov","Dec"),
staxx=T, cylindrical=T, srt=45)
#par(new=T)
#plot(xvals$x,burnMeans, xaxt="n", yaxt="n",
xlab="", ylab="", type="b",
cex=1, pch=16, lty=44, col="black", lwd=1.5, ylim=c(0,
max(burnMeans)))
#axis(4, pretty(c(0,max(burnMeans)),n=4))
#my replacement of your last three lines
# I only want to have one plot
scaleFactor=max(wetMeans)/max(burnMeans)
lines(x=seq(along=burnMeans), y=burnMeans*scaleFactor, lwd=1.5, lty=44,
type="b")
axis(4, at=pretty(c(0,max(burnMeans)),n=4)*scaleFactor,
labels=pretty(c(0,max(burnMeans)),n=4))
Explanation: I'm using only "one plot". The BurnMeans are scaled
by
scaleFactor and plotted into the first plot with lines(). For the axis I'm
using the scaled "at" values with not scaled "labels".
Hope this helps,
Moritz
_________________________
Moritz Grenke
http://www.360mix.de
-----Urspr?ngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von Andy Aldersley
Gesendet: Donnerstag, 20. Januar 2011 17:35
An: r-help at r-project.org
Betreff: [R] Scale of 2nd y-axis
Dear list,
My query follows on from a question I posted a few days ago. I have the
following 2 sets of data:
wetMeans[1] 9.904762[2] 6.344828[3] 6.346154[4] 6.855769[5] 9.074324[6]
9.953988[7] 13.482966[8] 14.546053[9] 10.841584[10] 9.752033[11]
6.739336[12] 8.955056burnMeans[1] 0.06214286[2] 0.05396552[3] 0.04096154[4]
0.05302885[5] 0.05831081[6] 0.07392638[7] 0.29969940[8] 0.25596217[9]
0.09316832[10] 0.14441057[11] 0.13180095[12] 0.05348315
which I am trying to plot on the same graph. I wish to plot the variable
"wetMeans" as bars and overlay "burnMeans" as a line, using
the same x-axis
(there are 12 observations in each set, corresponding to the months of the
year) but different y-axes. I have produced the following code which
addresses my previous issue (aligning the centre of each bar and the points
of the line plot); my problem now relates to the 2nd y-axis (which is being
used for the burnMeans data):
library(plotrix)
par(oma=c(1,1,1,1))par(las=1)
xvals <- barp(wetMeans, xlab="", ylab="",
main="TEST", col="grey",
names.arg=c("Jan","Feb","Mar","Apr","May",
"Jun","Jul","Aug","Sep","Oct","Nov","Dec"),
staxx=T, cylindrical=T, srt=45)
par(new=T)
plot(xvals$x,burnMeans, xaxt="n", yaxt="n",
xlab="", ylab="", type="b",
cex=1, pch=16, lty=44, col="black", lwd=1.5)
axis(4, pretty(c(0,max(burnMeans)),n=4))
As you can see when you plot the data, the 2nd y-axis does not have an
origin at 0. From a quick inspection of the graph it appears that the scale
of the 2nd y-axis is such that the 0 marker would not fit on the grid. My
question is therefore if there is a method by which I can shift the line
plot (burnMeans) upwards, so that both plotted data sets have their
respective y-axes beginning at 0.
Many thanks in advance,Andy
[[alternative HTML version deleted]]
______________________________________________
R-help at 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.