Philip de Witt Hamer
2010-Jan-10 19:27 UTC
[R] ordering of additional columns in forest plot in meta package
Hi, I am trying to add additional columns to a forest plot using the meta package. The study information and subgroup analysis plotting is handled properly. For this output the data is ordered first by subgroup label (rnd.subgroup1 in the example) and second decreasing size of totals ('n' in the example). The proper ordering of this data is confirmed by the color coding (black and red in the example) of the subgroup label. Also the "studlab","event" and "n" are all ordered correctly. The probIem now is that I cannot get the added columns ("rnd.subgroup1" and "rnd.subgroup2") to follow this same proper ordering. library(meta) # dummy data nr.studies <- 20 rnd.subgroup1 <- round(rnorm(nr.studies,1.5,.1),0) # random 1s and 2s rnd.subgroup2 <- c(letters[1:nr.studies]) # ordered unique letters lbls <- c(letters[1:nr.studies]) # letters as surrogate study labels 'author et al, year' event <- round(rnorm(nr.studies,10,5),0) # random event nrs event[event<0]<-0 # to avoid a negative value error n <- round(rnorm(nr.studies,100,25),0) # random totals mydata <- data.frame(cbind(lbls,rnd.subgroup1,rnd.subgroup2,rnd.subgroup3,event,n)) mydata a <- metaprop(event,n,studlab=lbls) a$rnd.subgroup1 <- addvar(a,mydata,"rnd.subgroup1",by.y="lbls") a$rnd.subgroup2 <- addvar(a,mydata,"rnd.subgroup2",by.y="lbls") grid.newpage() forest(a, studlab=lbls, comb.fixed=T,comb.random=F,overall=T, text.fixed="my title here", byvar=rnd.subgroup1, print.byvar=T, leftcols=c("studlab","rnd.subgroup1","rnd.subgroup2","event","n"), # sort order not right for 'rnd.subgroup1' and 'rnd.subgroup2' bylab=c("one","two"), sortvar=-n, col.i=rnd.subgroup1, col.by=c("royalblue"), xlim=c(0,.5) ) I suspect that it may have to do with an omitted indexing command in the forest function. Your input in kindly appreciated. Philip de Witt Hamer, MD PhD VU medical center dept neurosurgery PO Box 7057 1007 MB Amsterdam The Netherlands