Schreiber, Stefan
2008-Oct-02 16:04 UTC
[R] combining bar and line plots with multiple axes
Hey list, I have a barplot with a line plot overlayed (on the 2nd y axis) and it looks fine except that the origin (0) on the 2nd y axis (side=4) is not lining up with the origin on the 1st y-axis (side=2, from the barplot). Is there a way to either shift the 2nd y-axis (line plot) down or readjust the barplot axis? Just as a reference, here is the code: barplot2(temp$precip, names.arg=temp$year, ylim=c(0,300),axes=F) axis(2) par(new=T) plot(temp$year, temp$mat, axes=F, type="l", ylim=(0,25)) axis(4) Thanks!! Stefan [[alternative HTML version deleted]]
The updateusr function in the TeachingDemos package can be used to change the user coordinates of the current plot and may do what you want. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Schreiber, Stefan > Sent: Thursday, October 02, 2008 10:04 AM > To: r-help at r-project.org > Subject: [R] combining bar and line plots with multiple axes > > Hey list, > > I have a barplot with a line plot overlayed (on the 2nd y axis) and it > looks fine except that the origin (0) on the 2nd y axis (side=4) is > not > lining up with the origin on the 1st y-axis (side=2, from the barplot). > Is there a way to either shift the 2nd y-axis (line plot) down or > readjust the barplot axis? > > Just as a reference, here is the code: > > barplot2(temp$precip, names.arg=temp$year, ylim=c(0,300),axes=F) > axis(2) > par(new=T) > plot(temp$year, temp$mat, axes=F, type="l", ylim=(0,25)) > axis(4) > > > Thanks!! > > Stefan > > [[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.
Reasonably Related Threads
- Arranging two different types of ggplot2 plots with axes lined up
- Function that is giving me a headache- any help appreciated (automatic read )
- matrix transformation into 3 columns II.
- R combining vectors into a data frame but without a continuous common variable
- How to replace numeric value in the column contains Text (Factor)?