[R] dotplot as a background for multiple barchart plots (with Lattice)

From: Christian Charles <christian.charles_at_inrialpes.fr>
Date: Thu, 07 Apr 2011 15:46:41 +0200

Hi R users,

I'm kind stuck in my R experience...
I want to have a multiple barchart with n windows, but with the same background for each window, and I want that background to be a recorded dotplot.
First, is it possible ?
If so, I guess I have to call a record plot in the panel function but how ? As there is no panel.plot and I can't use the recorded plot as an argument for the panel.dotplot() call, I'm stuck. I think I close but I need some help.

Many thanks and regards,


### dummy data building

test <- data.frame(Subject=rep(c("A", "B", "C", "D"), each=6),

                    Type=rep(c("EEE", "FFF", "GGG", "HHH", "III", 
"JJJ"), times=4),

### data for regrouping all means

all <- data.frame(Type=levels(factor(test$Type)), MeanX = c(0), MeanZ = c(0))

### building means...

for(s in levels(factor(test$Subject)))

     tmp <- data.frame(Type = all$Type)
     for(t in tmp$Type)
             tmp$MeanX[tmp$Type == t] <- mean(test$MeanX[test$Type==t & 
             tmp$MeanZ[tmp$Type == t] <- mean(test$MeanZ[test$Type==t & 
     all$MeanX = all$MeanX + tmp$MeanX
     all$MeanZ = all$MeanZ + tmp$MeanZ

l <- length(levels(factor(test$Subject))) all$MeanX = all$MeanX/l
all$MeanX = all$MeanZ/l

### plot for means

meanplot <- dotplot(MeanX+MeanZ ~ Type, data=all, cex = 1.2, xlab="", ylab="",

     panel = panel.superpose,
     panel.groups = function(x, ..., group.number){
     panel.dotplot(x + (group.number - 1.5)/3, ... )

### test plot in order to see if there is something wrong.

### final plot

barchart( MeanX + MeanZ ~ Type|Subject,

          data=test ,
          scales = list(x = list(rot = 60)),
          layout=c(1, l),
          panel = function(...) {
             #panel.dotplot(meanplot) # so this is want I want, my 
recorded dotplot as a background...
             panel.grid(v = -length(levels(factor(test$Type))), h=0)

BTW, this R code might not be perfect and surely, there are better ways to build my data frames, but that's my newbie way to do it.

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 07 Apr 2011 - 15:20:28 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 Fri 08 Apr 2011 - 04:20:30 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