Hi, I have the following sample data
x <- c(1,2,1,1,2,3,1,2,3,2,3,1,2,2,1,3,2,3,1,3) y <- c(1,2,1,2,2,2,1,2,1,1,1,1,2,2,1,2,2,1,2,1) w <- c(1, 1, 1.5, 1, 1.2, 0.8, 0.9, 1.7, 1, 1.3, 1, 1, 0.7, 0.8, 1.4, 1.3, 1, 1, 0.9, 0.7) d1 <- data.frame(x,y,w) and I wish to build a x,y mosaic graphs that shows as labels both row percentages and number of cases. So far I have been using this script: require(gmodels) require(vcd) d2 <- xtabs(~ x + y, data=d1) mosaic ( d2, gp = shading_max, labeling_args = list( gp_labels = gpar(fontsize = 10, fontface = 1), rot_labels = c(0,90,90,0), gp_varnames = gpar(fontsize = 0, fontface = 2) ), main= "title", main_gp = gpar(fontsize = 16, fontface = 2), pop=FALSE ) d3 <- CrossTable(d1$x,d1$y) etichette <- ifelse(d2 < 5, "<5", paste(round(d3$prop.row*100, digits=1),"%\n(n=",d2,")", sep="")) labeling_cells(text = etichette, clip = FALSE, gp_text=gpar(fontsize=10))(d2) This works just fine but now I have to apply the weight w to the computation. I have modified the first part of the above script to d2 <-round(xtabs(w ~ x + y, data=d1), digits=0) mosaic ( d2, gp = shading_max, labeling_args = list( gp_labels = gpar(fontsize = 10, fontface = 1), rot_labels = c(0,90,90,0), gp_varnames = gpar(fontsize = 0, fontface = 2) ), main= "title", main_gp = gpar(fontsize = 16, fontface = 2), pop=FALSE ) but I have some difficulty with the labeling part. I can show number of observation in the labels using: d3 <- as.list(round(xtabs(w ~ x + y, data=d1)), digits=0) etichette <- ifelse(d2 < 5, "<5", paste("(n=",d3,")", sep="")) labeling_cells(text = etichette, clip = FALSE, gp_text=gpar(fontsize=10))(d2) but I would need to show row proportions, do you know how I can do that? Thanks, Luca Mr. Luca Meyer www.lucameyer.com R version 2.13.1 (2011-07-08) Mac OS X 10.6.8 [[alternative HTML version deleted]] ______________________________________________ R-help@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.