[R] question about mosaicplot and/or mosaic
dimitri.liakhovitski at gmail.com
Thu Jul 21 19:31:40 CEST 2011
Achim, this is great! Thanks a lot!
On Thu, Jul 21, 2011 at 1:09 PM, Achim Zeileis <Achim.Zeileis at uibk.ac.at> wrote:
> On Thu, 21 Jul 2011, Dimitri Liakhovitski wrote:
>> 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
>> For example:
>> 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))
>> mosaic(matrix(c(58, 15, 9, 13, 5,0), 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"))
>> Thank you!
>> Dimitri Liakhovitski
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help