I have a data set consisting of dummies, which looks like follows:
# Example data
set.seed(123)
data <- data.frame(x1 = rbinom(10, 1, 0.3),
x2 = rbinom(10, 1, 0.6),
x3 = rbinom(10, 1, 0.5))
I want to create a mosaic plot/grid plot (actually I am not sure how such a plot should be called), in which each 1-value is displayed in black and each 0-value is displayed in white. There should be no white space or any other color between the displayed lines.
An example of a plot I would like to create could be found in this paper on page 97:
I tried several different packages like ggplot2
or vcd
, but unfortunately I was not able to produce exactly the same plot. Any help or any hint for a package is highly appreciated!
The
image
function is perhaps the easiest way to display matrices with colors. You need to transpose and reverse it to have the order correct