[R] Tick marks that correspond with bars on barplot

Jim Lemon jim at bitwrit.com.au
Sat Aug 9 14:33:04 CEST 2008


On Fri, 2008-08-08 at 16:04 -0300, Megan J Bellamy wrote:
> 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. 
> 
Try this:

xpos<-barplot(...)
...
axis(1,at=xpos,labels=seq(1965,2005,by=5))

> Attached is the csv file. Any help with this would be greatly appreciated. Many thanks in advance,
> 
Unfortunately, the CSV file didn't make it, but the above works with
simulated data.

Jim



More information about the R-help mailing list