[R] Re flect Back to Back Histograms in x-axis?
(Ted Harding)
Ted.Harding at manchester.ac.uk
Mon Jun 8 16:55:17 CEST 2009
On 08-Jun-09 13:11:03, sedm1000 wrote:
> I've looked long and hard for this, but maybe I am missing something...
>
> There is a nice module that displays histograms reflected in the
> y axis, i.e.
> http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=136
>
> but is it possible to reflect in the x-axis, so to have two datasets,
> one pointing up and one down rather than left and right? I haven't
> been able to find a way to plot this way using the guide, or elsewhere.
>
> Thanks...
> --
[Sorry, there was a superfluous line in the code I posted previously.
Commented out below to show where it was]
Try along the lines of:
set.seed(54321)
X1 <- rnorm(500)
X2 <- rnorm(500)
##H1 <- hist(X1,breaks=0.5*((-8):8),ylim=c(-100,100))
H1 <- hist(X1,breaks=0.5*((-8):8),ylim=c(-100,100),col="red")
H2 <- hist(X2,breaks=0.5*((-8):8),plot=FALSE)
H3<-H2 ; H3$counts <- -H3$counts
plot(H3,add=TRUE,col="blue")
NB: The choice of breaks and ylim was made after a preliminary
inspection of hist(X1) and hist(X2).
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 08-Jun-09 Time: 15:50:48
------------------------------ XFMail ------------------------------
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 08-Jun-09 Time: 15:54:40
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list