[R] barchart producing incorrect number of barcharts when columns renamed

jim holtman jholtman at gmail.com
Thu Apr 26 14:08:15 CEST 2007


Check you column names on the first plot.  You have two of them called
"R Thalamus" and "R Mid Fron Gy".  This might be causing you problems.

On 4/26/07, Colm G. Connolly <Colm.Connolly at tcd.ie> wrote:
> On 25 Apr 2007, at 19:50, Deepayan Sarkar wrote:
>
> > You seem to have missed this footer that appears in every r-help
> > message. Your code is not reproducible, and not minimal by a long,
> > long, shot.
> >
>
> Indeed you are correct. My apologies.
>
> This more minimal code should demonstrate the problem. I've removed
> all references to external files and verified that I have the same
> problem without them.
>
> When I change the column names I get a 4x4 array of barcharts,
> whereas when I do not change the column names I correctly get the 5x5
> array.
>
> The question is what causes this discrepancy?
>
> library('lattice')
> rm(list=ls())
>
> textFontSize=6;
>
> clipping="(NOT Clipped)";
>
> roi.errs=data.frame(
>   cbind(
>         ##Group
>         c("ctrl", "ctrl", "short", "short", "long", "long"),
>         ##Subject
>         c("66101_2", "66112_2", "66119", "66121", "66026_3",
> "66030_2")),
>   cbind(
>         ##Sub-brick
>         c(0, 0, 0, 0, 0, 0),
>         ##Mean_1
>         c(0.546532, 6.057756, 0.241484, 8.861095, 6.712401, 6.714763),
>         ##Mean_2
>         c(0.541001, 1.821168, -0.071227, 7.387406, 4.164371, 6.196456),
>         ##Mean_3
>         c(-0.211658, 1.053770, 4.772759, 9.780944, 7.530651, 3.357583),
>         ##Mean_4
>         c(0.592144, -2.386457, 4.998830, 12.428849, 14.037164,
> 4.049794),
>         ##Mean_5
>         c(1.449212, 2.445002, -2.718933, 8.900946, 7.919560, 8.350304),
>         ##Mean_6
>         c(1.919896, 2.466083, -3.906275, 0.822132, 5.910088, 4.678836),
>         ##Mean_7
>         c(0.665386, -3.790489, 1.191782, 3.613919, 3.808240, 5.036492),
>         ##Mean_8
>         c(0.865090, 1.741351, 2.012702, 10.093662, 0.829254, 3.880265),
>         ##Mean_9
>         c(0.342638, -1.200232, 9.458908, 7.756559, 6.308535, 1.497788),
>         ##Mean_10
>         c(1.522509, 1.780352, 4.471669, -1.122842, 4.923762, 4.025056),
>         ##Mean_11
>         c(0.615833, 1.363775, 0.215138, 5.988049, 7.545206, 2.117970),
>         ##Mean_12
>         c(-0.932574, -1.140839, -5.778118, 5.749871, 8.312596,
> 4.937120),
>         ##Mean_13
>         c(-1.403353, 9.795787, 1.129139, 2.383282, 4.998841, 3.721432),
>         ##Mean_14
>         c(0.534640, 4.651436, -0.163107, 3.714310, 6.594728, 3.636995),
>         ##Mean_15
>         c(0.951416, 2.384751, -2.804867, 4.662075, 4.375787, 5.767994),
>         ##Mean_16
>         c(0.333624, -4.837685, -2.951958, -3.335181, 2.915522,
> 2.617556),
>         ##Mean_17
>         c(2.184298, 7.578843, -2.862990, 6.923186, -2.569342,
> 0.913788),
>         ##Mean_18
>         c(0.382605, 6.441820, 0.579722, -2.424237, 6.884646, 3.127198),
>         ##Mean_19
>         c(-0.737142, 3.306980, 2.417347, -7.521070, 6.570706,
> 1.556814),
>         ##Mean_20
>         c(0.545103, 8.721134, -1.766060, 21.433794, 5.829050,
> 4.031095)));
>
> colnames(roi.errs)=c("Group","Subject","Sub-
> brick","Mean_1","Mean_2","Mean_3","Mean_4","Mean_5","Mean_6","Mean_7",
> "Mean_8","Mean_9","Mean_10","Mean_11","Mean_12","Mean_13","Mean_14","Mea
> n_15","Mean_16","Mean_17","Mean_18",
> "Mean_19","Mean_20");
>
> roi.errs.names=names(roi.errs);
> ## ctrl
> roi.errs.ctrl<-roi.errs[roi.errs[,"Group"]=="ctrl", 4:length(roi.errs)]
> roi.errs.ctrl.subjects=roi.errs[roi.errs[,"Group"]=="ctrl", 2]
> ## short
> roi.errs.short<-roi.errs[roi.errs[,"Group"]=="short", 4:length
> (roi.errs)]
> roi.errs.short.subjects=roi.errs[roi.errs[,"Group"]=="short", 2]
> ## long
> roi.errs.long<-roi.errs[roi.errs[,"Group"]=="long", 4:length(roi.errs)]
> roi.errs.long.subjects=roi.errs[roi.errs[,"Group"]=="long", 2]
>
>
> roi.errs.ctrl.matrix=as.matrix(roi.errs.ctrl)
> roi.errs.short.matrix=as.matrix(roi.errs.short)
> roi.errs.long.matrix=as.matrix(roi.errs.long)
>
> #####################################
> ### WITH column name change
> #####################################
>
> roi.errs.ctrl.means=colMeans(roi.errs.ctrl.matrix)
> roi.errs.short.means=colMeans(roi.errs.short.matrix)
> roi.errs.long.means=colMeans(roi.errs.long.matrix)
> yylim=c(floor(min(roi.errs[, 4:length(roi.errs)])), ceiling(max
> (roi.errs[, 4:length(roi.errs)])))
>
> errs.Means=rbind(roi.errs.ctrl.means, roi.errs.short.means,
> roi.errs.long.means)
> rownames(errs.Means)=c('control', 'short', 'long')
> cat("errs.Means dimensions before col name change ", dim(errs.Means),
> "\n");
>
> colnames(errs.Means) = list("R Cing Gy", "R Smar Gy", "L Inf Fron Gy",
>           "R Thalamus", "R Mid Fron Gy", "L Mid Temp Gy", "L Inf Par
> Lbl",
>           "R Mid Fron Gy", "L Cing Gy", "R Thalamus", "R Mid Fron
> Gy", "R Lent Nuc",
>           "R Inf Fron Gy", "R Mid Temp Gy", "R Sup Par Lbl", "R Cere
> Ton",
>           "L Prec", "R Cere Ton", "L Pyramis", "R Prec Gy");
>
> cat("errs.Means dimensions after col name change ", dim(errs.Means),
> "\n");
>
> get(getOption("device"))()
> fontsize=trellis.par.get("fontsize");
> fontsize$text=textFontSize;
> trellis.par.set("fontsize", fontsize);
>
> print(barchart(errs.Means, groups=rownames(errs.Means), xlab='Mean
> Intensity',
>                main=paste("Mean Cluster Intensity for Errors",
> clipping),
>                ylab='Group', col=rainbow(length(rownames
> (errs.Means))), border=rainbow(length(rownames(errs.Means)))))
>
> #####################################
> ### WITHOUT column name change
> #####################################
>
> errs.Means=rbind(roi.errs.ctrl.means, roi.errs.short.means,
> roi.errs.long.means)
> rownames(errs.Means)=c('control', 'short', 'long')
>
> get(getOption("device"))()
> fontsize=trellis.par.get("fontsize");
> fontsize$text=textFontSize;
> trellis.par.set("fontsize", fontsize);
>
> print(barchart(errs.Means, groups=rownames(errs.Means), xlab='Mean
> Intensity',
>                main=paste("Mean Cluster Intensity for Errors",
> clipping),
>                ylab='Group', col=rainbow(length(rownames
> (errs.Means))), border=rainbow(length(rownames(errs.Means)))))
>
> Thanks,
>
> Regards,
> --
> Dr Colm G. Connolly
> School of Psychology and Institute of Neuroscience
> The Lloyd Building
> University of Dublin
> Trinity College, Dublin 2, Éire
> Tel: +353-1-896-8475
> Fax: +353-1-671-3183
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list