如何将马赛克图与xyplot结合起来?

时间:2013-10-12 12:43:13

标签: r lattice mosaic

我正在尝试重现this plot

enter image description here

它看起来像库格子中的xyplot,但我找不到将马赛克图与xyplot结合的方法。

有谁知道怎么做?

2 个答案:

答案 0 :(得分:4)

您只是在寻找内置于vcd ::: cotabplot

的面板功能
library(vcd)
data("alzheimer", package = "coin")
alz <- xtabs(~smoking + disease + gender, data = alzheimer)
cotabplot(~ smoking + disease | gender, data = alz, panel = cotab_coindep, n = 5000)

example http://img844.imageshack.us/img844/8407/1l6d.jpg

答案 1 :(得分:2)

以下是潜在数据的模拟:

    Smoker <- sample(c("yes", "no"), 100, T)
    Days <- sample(c("thu", "fri", "sat", "sun"), 100, T)
    Time <- sample(c("day", "night"), 100, T)
    Sex <- sample(c("m", "f"), 100, T)
    Value <- sample(1:10, 100, T)

    DF <- data.frame(Value, Smoker, Days, Time, Sex)

使用包vcd生成图:

    library(vcd)

    cotabplot(~ Smoker + Days + Time | Sex, data = DF, panel = cotab_mosaic, direction = "v")

编辑:上传剧情:

plot http://i41.tinypic.com/2mhg8ow.jpg