Skip to content

Lattice dotplots

3 messages · barbara.chaves at bayer.com, Peter Ehlers, Dieter Menne

#
On 2010-12-01 04:02, barbara.chaves at bayer.com wrote:
Try this (I've stripped out the unnecessary stuff; what
is it about *minimal* that seems to elude people?):

   p <- dotplot (ID ~ OUT | as.factor(BLOC) * LOC,
          data=dataset,pch=c(19,4,17,15),ylab="",xlab="OUT",
          fill.color = dataset$COL,
          TRT = dataset$TRT,
          panel = function(x, y, fill.color, TRT, ..., subscripts) {
            fill <- fill.color [subscripts]
            panel.dotplot(x, y,  col = fill, ...)
            panel.abline (v=mean(x[y=="A" & TRT =="T1"], na.rm=TRUE),
              col="green", lty=2)
          }
   )
   print(p)

Peter Ehlers
#
barbara.chaves wrote:
Thanks a lot for the nice self-contained example which certainly has cost
you some time. A bit of nitpicking: You could have improved it a little by
removing decorative stuff and using a lower degree of indentation to avoid
ugly line breaks in email. 

You were close by, but I believe that you ran into the trap of believing
that the dot in ID.TRT is something special in variable names as it is in c
or Pascal. The dot in names has sometimes a meaning for functions (try
methods("print")) but it is not possible to "get a part of it" in panel.dot. 

The workaround is simple: pass TRT, not ID.TRT. Everything else was fine,
some minor modifications were added.

Dieter

# Begin code
dataset <- expand.grid (
      LOC=c("LOC1", "LOC2"),
      # Better make it a factor immediately to avoid surprises later
      BLOC=as.factor(c(1,2,3)),
      ID=c("A", "B", "C", "D","E"),
      TRT=c("T1", "T2", "T3","T4"))
# replaced nested ifelse
dataset$COL <- factor(dataset$TRT,labels=c("green", "blue","orange","red"))

dataset$ID.TRT <- as.factor(paste(dataset$ID,dataset$TRT,sep="."))
dataset$OUT <- sample(50:60, 120, replace=TRUE)

# removed "as.factor". Corrected TRT
dotplot (ID ~ OUT | BLOC * LOC,
  data=dataset,pch=c(19,4,17,15),
  TRT = dataset$TRT,
  fill.color = dataset$COL,
  panel = function(x, y, TRT, ..., subscripts)
  {
    panel.dotplot(x, y,fill=fill.color,  ...)
    panel.abline (v=mean(x [y=="E" & TRT =="T1"],na.rm=TRUE),col="green",
lty=2)
  })