Achim, this is great! Thanks a lot! Dimitri On Thu, Jul 21, 2011 at 1:09 PM, Achim Zeileis <achim.zeil...@uibk.ac.at> wrote: > On Thu, 21 Jul 2011, Dimitri Liakhovitski wrote: > >> Hello! >> >> I am trying to build a mosaic plot that has different colors for each >> entry (cell). My data that goes into the plot is NOT really a >> contingency table and I would like each shape to have its own >> color.Looks like mosaic and mosaicplot treat the data as a contingency >> table and seem to allow different columns by "variable" only. Or am I >> mistaken? >> >> For example: >> >> library(stat) >> mosaicplot(matrix(c(58, 15, 9, 13, 5,0), 3, 2), >> main="",xlab="Share 0 to 100%",ylab="Share 0 to 100%",color=c(3,2)) >> >> or: >> >> library(vcd) >> mosaic(matrix(c(58, 15, 9, 13, 5,0), 3, 2), >> highlighting=1,highlighting_fill=c(3,2)) > > I think mosaicplot() always recycles the colors along the last variable. But > with mosaic() you can do almost whatever you like. Above, you have selected > a particular variable/margin for highlighting, i.e., did what mosaicplot() > also does (but not what you wanted to do). > > The simplest way to achieve what you want to do, is specify the graphical > parameters "gp" directly. These can be of the same dimension as the data. > For example: > > ## data > d <- matrix(c(58, 15, 9, 13, 5,0), 3, 2) > > ## colors > col <- matrix(hcl(0:5 * 60), 3, 2) > > ## plots > mosaic(d, gp = gpar(fill = col)) > mosaic(d, gp = gpar(col = col, fill = col)) > mosaic(d, gp = gpar(col = col, lwd = 5, fill = "white")) > > etc. > > hth, > Z > >> Thank you! >> -- >> Dimitri Liakhovitski >> marketfusionanalytics.com >> >> ______________________________________________ >> 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. >> >
-- Dimitri Liakhovitski marketfusionanalytics.com ______________________________________________ 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.