[R] color query in mosaic in package vcd
Achim Zeileis
Achim.Zeileis at uibk.ac.at
Fri Feb 8 07:20:18 CET 2013
On Fri, 8 Feb 2013, Richard M. Heiberger wrote:
> require(vcd)
> mosaic(matrix(1:6, 2, 3), gp=gpar(fill=c("red","gray","blue")), main="three
> colors in each row")
> mosaic(matrix(1:3, 1, 3), gp=gpar(fill=c("red","gray","blue")), main="only
> one color in each row")
> I anticipated three colors in the second plot. My guess is that there
> is a matrix subscript without drop=FALSE somewhere on the inside of one
> of the functions.
No, it's more subtle.
If the dimension of the data (1, 3) is not the same as that of the fill
(NULL), they are recycled along the last dimension (see Section 3 of
vignette("strucplot", package = "vcd")). Thus supplying a suitable fill
matrix works:
mosaic(matrix(1:3, 1, 3),
gp = gpar(fill=matrix(c("red","gray","blue"), 1, 3)))
David: The reason why Rich's original code does not work properly is that
the recycling is not triggered properly. In line 160 of strucplot.R we
check if(length(par) < size) which is not the case here and hence the
dimension is not added. I think we could do
if (length(par) < size | is.null(dim(par)))
aperm(array(par, dim = rev(d))) else par
That fixes the problem.
Best,
Z
> This is with
> Package: vcd
> Version: 1.2-13
> Date: 2012-02-19
>
> on
> version.string R Under development (unstable) (2013-02-02 r61822)
> platform i386-w64-mingw32
> arch i386
> os mingw32
> system i386, mingw32
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list