[R] A horizontal or vertical line draw on mosaic plot?
Sang Chul Choi
choi at biology.rutgers.edu
Fri May 2 22:02:22 CEST 2008
Thank you, Dieter, very much for your answer.
I'd rather avoid using mosaic. I think that I need to read more about
"vcd" manual you mentioned. One quick question? Is it possible to
color each cells with all different colors with "mosaicplot"? I have
used "mosaic" function to do coloring each cells depending on my
favor. I mean, I can color any cell with any color with "mosaic" but I
could not figure it out with "mosaicplot." Is it possible to color any
cell with any color with "mosaicplot" function?
I will greatly appreciate any help.
Thank you,
Sang Chul
On May 2, 2008, at 1:41 PM, Dieter Menne wrote:
> Sang Chul Choi <Choi <at> biology.rutgers.edu> writes:
>
>> I want to have a horizontal line on a mosaic plot with "vcd" package.
>> This would give me an idea where is 0.5 proportion in a cell. Using
>> "mosaicplot" function of "graphics" package, I can draw a line using
>> "abline." But, with "mosaic" function of "vcd" package, I have tried
>> to use "abline" function, which complains "plot.new has not been
>> called yet".
>>
>> Is there a way to draw lines across a mosaic plot?
>>
>> ========================================================
>> library(vcd)
>> music = c(210, 194, 170, 110,
>> 190, 406, 730, 290)
>> dim(music) = c(2, 4)
>> dimnames(music) = list(Age = c("Old", "Young"),
>> Education = c("High", "Low", "Upper",
>> "Lower"))
>> mosaic(music, keep_aspect_ratio=FALSE)
>> abline(h=0.5)
>> Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
>> plot.new has not been called yet
>> ========================================================
>
> Not that easy. vcd uses grid graphics, which is a medium-to-low
> level package;
> for example, lattice also uses grid graphics, and abline would not
> help.
>
> You could draw directly using grid graphics, but it may be a bit of
> reading. Use
> the example on the bottom of the strucplot page as a starter, which
> changes
> color. Also see page 17 of strucplot.pdf in the doc-directory of vcd
> for an
> example how to draw a frame around a rectangle.
>
>
> grid.edit("rect:Class=1st,Sex=Male,Age=Adult,Survived=Yes",
> gp = gpar(fill = "red"))
>
> Dieter
>
> ______________________________________________
> 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