[R] Help with ooplot(gplots) and error bars

Marc Schwartz MSchwartz at MedAnalytics.com
Sun Nov 21 17:59:47 CET 2004


On Sun, 2004-11-21 at 12:31 +0100, Jean-Louis Abitbol wrote:
> Dear All
> 
> I am trying to graph a proportion and CI95% by a factor with ooplot (any
> other better solution ?)
> 
> It works well until I try to add the confidence interval.
> 
> this is the error message and and a description of the data:
>   
>  > dat1
>         PointEst
> TT1   1      3.6
> TT2   2      5.0
> TT3   3      5.8
> TT4   4     11.5
> TT5   5      7.5
> TT5   6      8.7
> TT7   7     17.4
> > dat2
>         Lower
> TT1   1   1.0
> TT2   2   2.2
> TT3   3   2.7
> TT4   4   6.7
> TT5   5   3.9
> TT5   6   4.6
> TT7   7  11.5
> > dat3
>         Upper
> TT1   1  12.3
> TT2   2  11.2
> TT3   3  12.1
> TT4   4  19.1
> TT5   5  14.2
> TT5   6  15.6
> TT7   7  25.6
> > ooplot(dat1,type="barplot",col=rich.colors(7,"temperature"),names.arg=c("X","Y","Z","A","B","C","D"),plot.ci=T,
> + ci.l=dat2,ci.u=dat3, xlab="Treatment", ylab="Percent Normalized
> Patients")
> Error in ooplot.default(dat1, type = "barplot", col = rich.colors(7,
> "temperature"),  : 
>         'height' and 'ci.u' must have the same dimensions.
> 
> I have tried various ways of supplying ci.l and ci.u (including a
> vector)
> 
> 
> Thanks for the help that anyone can bring,
> 
> Regards, JL


It appears that ooplot() is built upon barplot2() to an extent.

When I wrote barplot2(), in the case of plotting CI's, it expects that
the primary data structure ('data' in ooplot, 'height' in barplot2) have
the same dimensions as 'ci.l' and 'ci.u'.

Thus, for example:

barplot2(dat1[, 2], col = rich.colors(7,"temperature"), 
       names.arg = c("X", "Y", "Z", "A", "B", "C", "D"), plot.ci = TRUE,
       ci.l = dat2[, 2], ci.u = dat3[, 2], xlab = "Treatment", 
       ylab = "Percent Normalized Patients")

will work. Note that I am explicitly passing the requisite data vectors
for 'height' and the CI's to the function.

In the case of ooplot(), it appears to require that the 'data' argument
have at least two columns, which requires that you pass 'dat1' as a two
dimensional structure and not dat1[, 2] as a vector.

In this case, since ooplot is built upon barplot2, your call to ooplot
fails when the check of the 'data' and 'ci.u' dimesional structure takes
place.

The reason for the failure (even though all three of your data
structures appear to be of the same shape initially), is that ooplot
does:

 if (by.row) 
    data <- as.matrix(data)
 else data <- t(as.matrix(data))

which results in your dat1 being changed from a 7 x 2 matrix to a 2 x 7
matrix.

So 'data' now looks like:

> data
         TT1 TT2 TT3  TT4 TT5 TT6  TT7
         1.0   2 3.0  4.0 5.0 6.0  7.0
PointEst 3.6   5 5.8 11.5 7.5 8.7 17.4


ooplot then does:

height <- data[-1, , drop = FALSE]


to create 'height' which is used later in the function, as it is in
barplot2().


So 'height' now looks like:

> height
         TT1 TT2 TT3  TT4 TT5 TT6  TT7
PointEst 3.6   5 5.8 11.5 7.5 8.7 17.4


The actual checks in the ooplot code (taken verbatim from barplot2) that
compare the dimensions of the 'height' argument and the CI's is:

  if (any(dim(height) != dim(ci.u))) 
     stop("'height' and 'ci.u' must have the same dimensions.")
  else if (any(dim(height) != dim(ci.l))) 
     stop("'height' and 'ci.l' must have the same dimensions.")


Due to the transformations above however, 'height' is now a 1 x 7
matrix, whereas your dat2 and dat3 are 7 x 2 matrices. Hence the
failure.

So, I suspect that Greg (who I have cc:'d here) needs to look at the
ooplot code to make similar transformations on the 'ci.l' and 'ci.u'
arguments as he is on the 'data' argument to remove the error.

Short term, you have (at least) four options:

1. Use barplot2() as I note above

2. You can modify your call to ooplot(), by using t() on the 'ci.l' and
'ci.u' arguments as follows:

ooplot(dat1, type = "barplot", col = rich.colors(7,"temperature"), 
       names.arg = c("X", "Y", "Z", "A", "B", "C", "D"), plot.ci = TRUE,
       ci.l = t(dat2[, 2]), ci.u = t(dat3[, 2]), xlab = "Treatment", 
       ylab = "Percent Normalized Patients")


3. As Frank has mentioned, you can use his Dotplot() function.

4. Similar to Dotplot() in a fashion, is the plotCI() function, which is
also in Greg's gplots package.


If you stay with the barplot type of graph, you should consider changing
your colors, as the CI's are difficult to discern in the first two
columns at least.

HTH,

Marc Schwartz




More information about the R-help mailing list