An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110602/e0af7961/attachment.pl>
Adding a line to a beside=TRUE barplot
3 messages · Galen Moore, Peter Ehlers
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]]
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:
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]]