[R] Tick marks that correspond with bars on barplot

Megan J Bellamy bellammj at gov.ns.ca
Fri Aug 8 21:04:07 CEST 2008

Hello all,

I have created a barplot that shows change in hardwood/softwood density from 1965 to 2005 in 5 year periods (1965,1970, etc). I would like to have an X-axis where the labels for the years line up after every two bars in the plot (there is one bar for hardwood, and another for softwood). Below is my script:

density<-read.table("F:\\Megan\\Vtest.csv", header=TRUE, sep=",")
attach (density)
barplot(DENSITY,YEAR, col=c("blue", "green", "green", "blue", "blue", "green", "blue", "green", "green", "blue", "green", "blue", "blue", "green" , "green", "blue", "blue", "green"))
legend(1,85,c("Softwood", "Hardwood"), fill=c("blue", "green"), bty="n")
title(ylab="Density of Softwood and Hardwood by percent (%)")
title(xlab="Year of measurement")
title(main="Change in Softwood and Hardwood Density between 1965-2005 for PSP #80")
axis(2, at=NULL)

I have tried using the tck, axis.lty functions with no luck and have also tried
axis(1, at=YEAR) # but only the first year (1965) comes up. 

Attached is the csv file. Any help with this would be greatly appreciated. Many thanks in advance,


More information about the R-help mailing list