[R] abline() plot order

Al Piszcz apiszcz at solarrain.com
Thu Aug 7 19:01:08 CEST 2003


Marc:

I am interested in having only 'y' or 'x' axis tick
bars light gray across graph.

I did not realize there was a barplot2, thank you.

I used your second technique (add=TRUE) and it works!
Thank you very much for the speed of reply and quality
of the options.

The plot looks very good with the lines behind the bars!




I've been look at par and axTicks, and found everything
I need except control of the Y tickmarks, major and minor.
It is probably in there I just have not located it.




On Thu, 7 Aug 2003,
Marc Schwartz wrote:

> Date: Thu, 07 Aug 2003 11:41:20 -0500
> From: Marc Schwartz <MSchwartz at MedAnalytics.com>
> To: Al Piszcz <apiszcz at solarrain.com>
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] abline() plot order
>
> On Thu, 2003-08-07 at 11:07, Al Piszcz wrote:
> > I am performing this sequence
> >
> > barplot
> > title
> > legend
> > abline
> >
> > When abline renders the lines they appare to be in the layer
> > above the bars in the graph. Is there a way to make them
> > render first or 'behind' the bars?
> >
> > Thanks.
>
>
> Are you using abline() for a single line or for a grid?
>
> barplot2() in the 'gregmisc' package on CRAN can help with either
> scenario.
>
> If you want a grid behind the bars, use 'plot.grid = TRUE' in barplot2.
> The default will draw thin dotted lines behind the bars at each axis
> tick mark. You can specify the line type and width for the grid as well.
>
> Example:
>
> barplot2(1:5, plot.grid = TRUE)
>
> If you want a single line (ie. a benchmark), you could use barplot2()
> the first time to draw the chart, use abline() to draw your single line
> and then use barplot2() again, with the 'add = TRUE' argument, which
> would re-draw the bars over the existing plot.
>
> Example:
>
> barplot2(1:5)
> abline(h = 2)
> barplot2(1:5, add = TRUE)
>
>
> An alternative to using barplot2() would be to use par(new = TRUE) as
> well. This will enable you to add a new plot to the existing figure.
>
> First case:
>
> barplot(1:5)
> abline(h = axTicks(2), lty = "dotted")
> par(new = TRUE)
> barplot(1:5)
>
>
> Second case:
>
> barplot(1:5)
> abline(h = 2)
> par(new = TRUE)
> barplot(1:5)
>
> See ?axTicks and ?par for additional information.
>
> I'll make a note to myself to add an option to barplot2 for a single
> line that can be added behind the bars. Pretty easy fix.
>
> HTH,
>
> Marc Schwartz
>
>




More information about the R-help mailing list