Search code examples
rlatticemosaic

How to combine a mosaic plot with a xyplot?


I'm trying to reproduce this plot:

enter image description here

It looks like a xyplot in library lattice, but I couldn't find a way to combine a mosaic plot with a xyplot.

Does anyone know how to do it?


Solution

  • Here is a simulation of potential data:

        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)
    

    The plot is produced using package vcd:

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

    EDIT: uploaded the plot:

    plot