I want to create a mosicplot (2x2), where the counterpart have the same color.
So the mosaicplot should have a colorpalette like:
Here is the structure of the data i used for the graphic:
data <- data.frame(G1 = c("A", "B", "B", "A", "B", "B", "B", "B", "B", "B", "B"),
G2 = c("A", "A", "A", "B", "A", "A", "A","A", "B", "B", "B"))
I already tried to solve this with defining a third variable, which is then defining the colors:
data$C1 <- ifelse((data$G1 == "A" & data$G2 == "A") | (data$G1 == "B" & data$G2 == "B") ,
data$C1 <- "1", data$C1 <- "0")
ggplot(data = data) +
geom_mosaic(aes(x = product(G1, G2), fill = C1))
Unfortunately this results in:
Maybe someone knows a solution, whereby these little stripes are not visible (for example the blue line in field G1 == B and C1:G2 = 1:A)?
Thanks