Hi I could only find some discussion on this wrt lattice graphics (which I'm not using). Apologies if I'm missing something obvious. I'd like to produce 3 rug plots under a kernel density plot for a population. The population is subdivided into 3 subpopulations, which I'd like the rug plots to highlight. Naturally, when I do 3 rug plots, they all plot over each other. I'd like 3 parallel rug plots along the x-axis. But how. Thanks in advance, Quin [[alternative HTML version deleted]]
you could use different colours, e.g., x1 <- rnorm(100, -2.5, 1) x2 <- rnorm(100, 0, 1) x3 <- rnorm(100, 2.5, 1) x <- c(x1, x2, x3) plot(density(x)) rug(x1, col = "red") rug(x2, col = "black") rug(x3, col = "blue") or something like the following: plot(density(x)) len <- 0.005 ds <- 0.001 segments(x1, -1, x1, 0) segments(x2, 0 + ds, x2, len) segments(x3, len + ds, x3, 2*len) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Quin Wills" <wills at stats.ox.ac.uk> To: <r-help at stat.math.ethz.ch> Sent: Tuesday, July 17, 2007 12:50 PM Subject: [R] multiple rugs on a single plot> Hi > > > > I could only find some discussion on this wrt lattice graphics > (which I'm > not using). Apologies if I'm missing something obvious. > > > > I'd like to produce 3 rug plots under a kernel density plot for a > population. The population is subdivided into 3 subpopulations, > which I'd > like the rug plots to highlight. Naturally, when I do 3 rug plots, > they all > plot over each other. I'd like 3 parallel rug plots along the > x-axis. But > how. > > > > Thanks in advance, > > Quin > > > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
The rug function will take line and position arguments for the location of the rug plot, so you can do something like:> rug( x1, line=0 ) > rug( x2, line=1 ) > rug( x3, line=2 )Where line=0 means right on the x axis, line=1 means 1 textline height below the x axis (-1 would be the same distance above the x axis). Or pos=y will plot the rug plot at the specified y value (and you can give it y values below the y-axis). You should probably make sure to leave enough room for the rug plots to not be crowded and look at the other graphical options for how the rug plot will look. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Quin Wills > Sent: Tuesday, July 17, 2007 4:51 AM > To: r-help at stat.math.ethz.ch > Subject: [R] multiple rugs on a single plot > > Hi > > > > I could only find some discussion on this wrt lattice > graphics (which I'm not using). Apologies if I'm missing > something obvious. > > > > I'd like to produce 3 rug plots under a kernel density plot > for a population. The population is subdivided into 3 > subpopulations, which I'd like the rug plots to highlight. > Naturally, when I do 3 rug plots, they all plot over each > other. I'd like 3 parallel rug plots along the x-axis. But how. > > > > Thanks in advance, > > Quin > > > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >