Skip to content

Adding a line to a beside=TRUE barplot

3 messages · Galen Moore, Peter Ehlers

#
On 2011-06-02 13:09, Galen Moore wrote:
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, it works beautifully!  I'd not caught the use of colMeans() as
the path to useable x-coordinates, and was fixated on the existing
bargraph's x-vector for this purpose.

Ref your Q, I guess I had the lattice reference in there as a vestige of
other attempts to get the job done with barchart i/o barplot.

Galen

-----Original Message-----
From: Peter Ehlers [mailto:ehlers at ucalgary.ca] 
Sent: Friday, June 03, 2011 02:45
To: galen.a.moore at gmail.com
Cc: r-help at r-project.org
Subject: Re: [R] Adding a line to a beside=TRUE barplot
On 2011-06-02 13:09, Galen Moore wrote:
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