[R] combining bar and line plots with multiple axes

Greg Snow Greg.Snow at imail.org
Thu Oct 2 18:19:51 CEST 2008


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.



More information about the R-help mailing list