[R] Barplot and line x-axis positions

Greg Snow Greg.Snow at imail.org
Wed Jan 19 18:15:50 CET 2011


You can use the updateusr function in the TeachingDemos package to get them to match. 

Sent from my iPod

On Jan 18, 2011, at 10:05 AM, "Andy Aldersley" <ajaldersley at hotmail.co.uk> wrote:

> 
> 
> 
> 
> 
> Hello all,
> Hoping that there is a fairly simple solution to my query...
> I'm trying to overlay a line plot of some data onto a barplot of different data. The y-axes are different for each set of data but the x-axes are the same (1:12, corresponding with 12 months of observations). The problem I'm having is that the centre of the bars and the points on line don't match up, which is making the whole thing look untidy. I'm wondering if there is a way for me to specify the positions of the centre of each bar on the graph. The code I have is as follows:
> xvals <- barplot(wetMeans[,i], yaxt='n', axisnames=F, xlab='', ylab='', main=names[i], border=F, cex.main=0.7)par(new=T)plot(burnMeans[,i], yaxt='n', xlab='', ylab='', type='b', cex=1, pch=16, lty=44, col='black', lwd=1.5)
> As you can see I have suppressed the y-axis so this isn't a problem.I have also tried using the barp function in the plotrix package. This solved the problem of centring the bars on the graph, but when I overlay the line it seems to use different tick points on the x-axis. Again, I'm not sure why this is but if there is a quick fix that would be much appreciated.
> library(plotrix)xvals <- barp(wetMeans[,i], xlab='', ylab='', main=names[i], col='grey')par(new=T)plot(burnMeans[,i], yaxt='n', xlab='', ylab='', type='b', cex=1, pch=16, lty=44, col='black', lwd=1.5)
> I get the same result even if I suppress the x-axis in the plot command.
> Many thanks in advance,
> Andy
> 
> 
> 
> 
>                         
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.



More information about the R-help mailing list