[R] abline() plot order

Marc Schwartz MSchwartz at medanalytics.com
Thu Aug 7 19:30:52 CEST 2003

On Thu, 2003-08-07 at 12:01, Al Piszcz wrote:
> 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.


Your most flexible option on the tick mark locations is to use axis(),
which allows you to specify the locations. Use 'axes = FALSE' in
conjunction with barplot().  See ?axis for more information.


# draw the barplot without axes
barplot(1:5, axes = FALSE)

# Now draw the 'minor' tick marks as short lines
# and do not plot any labels
axis(2, at = seq(0, 5, 0.5), lwd = 1, tck = -0.01, 
     labels = FALSE)

# Now draw the 'major' tick marks with slight longer and thicker
# lines with labels
axis(2, at = 0:5, lwd = 2, tck = -0.015)

# Now draw the grid lines at the major tick marks in gray
# If you want the lines at the 'minor' tick marks 
# use: abline(h = seq(0, 5, 0.5), lty = "solid", col = "gray90")
# adjust the line type and color as you desire. See ?colors
abline(h = 0:5, lty = "solid", col = "gray90")

# Now replot the bars so they are over the lines
par(new = TRUE)
barplot(1:5, axes = FALSE)



More information about the R-help mailing list