[R] Barplot axis titles

Jim Lemon jim at bitwrit.com.au
Thu Feb 11 06:49:08 CET 2010


On 02/11/2010 01:03 PM, RagingJim wrote:
>
> Now, I think I am making this harder than it seems, but...
>
> I am writing a script that will allow me to pull any csv file with annual
> rainfall and plot it into a bar plot. The problem I am facing is that the
> different sites have recorded data for a different number of years. This
> means that every csv file has a different number of values.
>
> I need to somehow get a label at every 10 or 20 year points, and it has be
> able to allow for the fact that some files have 50 readings, and others have
> 200 readings.
>
> Now, if I use this:
>
> #axis(1,at=seq(1,rows,10),tcl=-0.5,labels=c(kent[1,2],kent[11,2],kent[21,2],kent[31,2],kent[41,2],kent[51,2],kent[61,2],kent[71,2],kent[81,2],kent[91,2]...
>
> I can get it for one file, but as soon as a file has a diff number of
> values, it does not work.
>
> The best I have been able to come up with is this:
>
> barplot(Ann,main=title, xlab="Year",ylab="Rainfall
> (mm)",ylim=c(0,ymax),col="blue",space=0,names.arg=c(kent[,2]),cex.names=0.8)
>
> however I cannot control how often the labels occur. I am sure there is an
> easy way to do this, but I cannot find it. I assume it will have something
> to do with names.arg, but I am not sure how to write what i want to write.

Hi RagingJim,

How about this?

dimkent<-dim(kent)
axis.ticks<-seq(kent[1,2],kent[dimkent[1],2],by=20)
if(kent[dimkent[1],2]%%20) axis.ticks<-axis.ticks[-length(axis.ticks]
barplot(Ann,main=title, xlab="Year",ylab="Rainfall (mm)",
  ylim=c(0,ymax),col="blue",space=0,
  names.arg=axis.ticks,cex.names=0.8)

Jim



More information about the R-help mailing list