[R] Connecting lines across missing data points, xyplot

Doran, Harold HDoran at air.org
Thu Jun 26 18:02:00 CEST 2008


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.
> 



More information about the R-help mailing list