Re: [R] Connecting lines across missing data points, xyplot

From: Doran, Harold <HDoran_at_air.org>
Date: Thu, 26 Jun 2008 12:02:00 -0400


Maybe approx() will work?

> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of David Afshartous
> Sent: Thursday, June 26, 2008 10:26 AM
> To: r-help_at_r-project.org
> Subject: [R] Connecting lines across missing data points, xyplot
>
>
>
> All,
>
> I have data across 5 time points that I am graphing via
> xyplot, along with error bars. For one of the variables I
> have missing data for two of the time points. The code below
> is okay but I can't seem to get the lines to connect across
> the missing time points. Does anyone now how to rectify this?

>
> Cheers,
> David Afshartous
>
>
>
> library(lattice)
> ## the data
> junk = data.frame(
> Visit = as.factor(rep(seq(1,5), 2)),
> Drug = rep(c("D", "P"), each = 5),
> Aldo = c(13, NA, NA, 15, 14, 12, NA, NA, 14, 13), SE.Aldo =
> c(3, NA, NA, 3, 3, 2, NA, NA, 2, 2), lower.ci.Aldo = c(10,
> NA, NA, 12, 11, 10,NA, NA, 12, 11), upper.ci.Aldo = c(16,
> NA, NA, 18, 17, 14, NA, NA, 16, 15)
> )
>
> ## functions for the error bars
> prepanel.ci <- function(x, y, ly, uy, subscripts, ...) {
> x <- as.numeric(x)
> ly <- as.numeric(ly[subscripts])
> uy <- as.numeric(uy[subscripts])
> list(ylim = range(y, uy, ly, finite = TRUE)) } panel.ci
> <- function(x, y, ly, uy, subscripts, pch = 16, ...) {
> x <- as.numeric(x)
> y <- as.numeric(y)
> ly <- as.numeric(ly[subscripts])
> uy <- as.numeric(uy[subscripts])
> panel.arrows(x, ly, x, uy, col = "black",
> length = 0.25, unit = "native",
> angle = 90, code = 3)
> panel.xyplot(x, y, pch = 16, ...)}
>
>
> ## the plot, but visit 1 not connected to visit 4 xyplot(Aldo
> ~ as.numeric(Visit), xlab="Visit", ylab="Aldo",
> groups=Drug,
> data=junk,
> ly = junk$lower.ci.Aldo,
> uy = junk$upper.ci.Aldo,
> prepanel = prepanel.ci,
> panel = panel.superpose,
> panel.groups = panel.ci,
> type="b",
> auto.key = list(space = "top", text = c( "D","P"),
> points = FALSE, lines = TRUE, columns=2), par.settings =
> list(superpose.line = list(lty = c(1,5), col=c('black',
> 'black') ) ) )
>
> ______________________________________________
> 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.
>



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. Received on Thu 26 Jun 2008 - 16:12:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 26 Jun 2008 - 16:31:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive