[R] Tick marks that correspond with bars on barplot

Mark Difford mark_difford at yahoo.co.uk
Fri Aug 8 15:45:03 CEST 2008


Hi Megan,

>> 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).

It isn't clear to me from your description what you really want (I found no
attachment)? What you seem to be trying to get is a tickmark/label at the
centre/midpoint of each yearly grouping. If so, then look at the examples
that the author of barplot() has provided, and _in particular_ read what the
author of the method says under "Value". You use the colMeans of the object
returned by barplot() to position labels.

Regards, Mark.


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. 
> 
> Attached is the csv file. Any help with this would be greatly appreciated.
> Many thanks in advance,
> 
> Megan
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/Tick-marks-that-correspond-with-bars-on-barplot-tp18890762p18892131.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list