[R] Adding a line to a beside=TRUE barplot

Peter Ehlers ehlers at ucalgary.ca
Fri Jun 3 10:44:51 CEST 2011


On 2011-06-02 13:09, Galen Moore wrote:
> Greetings –
>
>
>
> Grateful for any help on this one:
>
>
>
> In the following demo code, I am trying to get the points in the line to
> appear over the same x-axis labels as are used by the paired Bars.  It
> appears, however, that R/lattice ignores the x-axis points used by the bars
> and plots the x points for the line at ½ points.
>
>
>
> Can you help me tweak this code so that the nth bump in the line appears
> over the same nth pair of bars?  I’m open to any options besides
> lattice/barplot.
>
>
>
> library(lattice)
>
> aa<- abs(rnorm(c(1:10)))*5
>
> bb<- abs(rnorm(c(1:10)))*5
>
> cc<- abs(rnorm(c(1:10)))*5
>
>
>
> dd<- as.matrix(cbind(aa, bb))
>
>
>
> barplot(t(dd), beside=TRUE, ylim=c(0,10))
>
> lines(cc)

What's lattice doing here? barplot() is not a lattice function.

Careful reading of the help page for barplot and study
of the examples will lead you to:

   mp <- barplot(t(dd), beside=TRUE)
   mp
   lines(colMeans(mp), cc, col=2, lwd=3)


Peter Ehlers

>
>
>
> Many thanks,
>
>
>
> Galen
>
>
> 	[[alternative HTML version deleted]]
>



More information about the R-help mailing list