Afshartous, David
2009-Sep-26 18:05 UTC
[R] Lattice, stripplot (xyplot), plotting data with median line, numeric x-axis
All, On p.52 of Deepayan Sarkar's Lattice book there is a nice plot of showing residuals with median lines superimposed or various groups: library("lattice") stripplot(sqrt(abs(residuals(lm(yield~variety+year+site)))) ~ site, data = barley, groups = year, jitter.data = TRUE, type = c("p", "a"), fun median) Suppose we wanted to make a similar plot for a numeric x-axis. Is there any way to do this with stripplot or does one have to xyplot and presumably panel functionality to get the median line? This does not work: barley$site.numeric =as.numeric(barley$site) stripplot(sqrt(abs(residuals(lm(yield~variety+year+site)))) ~ site.numeric, data = barley, groups = year, jitter.data = TRUE, type = c("p", "a"), fun = median) Any tips much appreciated. For my data I had made my x-axis a factor but forgot that this doesn't work since the intervals are not equally spaced. Thanks! David
Felix Andrews
2009-Sep-27 11:22 UTC
[R] Lattice, stripplot (xyplot), plotting data with median line, numeric x-axis
Hi David, stripplot is for numeric vs categorical data (and is a thin wrapper around xyplot). Just change stripplot to xyplot and it will work. -Felix 2009/9/27 Afshartous, David <DAfshartous at med.miami.edu>:> All, > > On p.52 of Deepayan Sarkar's Lattice book there is a nice plot of showing > residuals with median lines superimposed or various groups: > > library("lattice") > stripplot(sqrt(abs(residuals(lm(yield~variety+year+site)))) ~ site, > > data = barley, groups = year, jitter.data = TRUE, type = c("p", "a"), fun > median) > > > Suppose we wanted to make a similar plot for a numeric x-axis. ?Is there any > way to do this with stripplot or does one have to xyplot and presumably > panel functionality to get the median line? ?This does not work: > > barley$site.numeric =as.numeric(barley$site) > > stripplot(sqrt(abs(residuals(lm(yield~variety+year+site)))) ~ site.numeric, > ? ?data = barley, groups = year, jitter.data = TRUE, type = c("p", "a"), > fun = median) > > > Any tips much appreciated. ?For my data I had made my x-axis a factor but > forgot that this doesn't work since the intervals are not equally spaced. > > Thanks! > David > > ______________________________________________ > R-help at r-project.org 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. >-- Felix Andrews / ??? Postdoctoral Fellow Integrated Catchment Assessment and Management (iCAM) Centre Fenner School of Environment and Society [Bldg 48a] The Australian National University Canberra ACT 0200 Australia M: +61 410 400 963 T: + 61 2 6125 1670 E: felix.andrews at anu.edu.au CRICOS Provider No. 00120C -- http://www.neurofractal.org/felix/