# NOT RUN {
data(titanic)
ggplot(data = titanic) +
geom_mosaic(aes(x = product(Class), fill = Survived)) +
geom_mosaic_text(aes(x = product(Class), fill = Survived))
ggplot(data = titanic) +
geom_mosaic(aes(x = product(Class, Sex), fill = Survived),
divider = c("vspine", "hspine", "hspine")) +
geom_mosaic_text(aes(x = product(Class, Sex), fill = Survived),
divider = c("vspine", "hspine", "hspine"), size = 2)
ggplot(data = happy) +
geom_mosaic(aes(x = product(health), fill = happy), na.rm = TRUE, show.legend = FALSE) +
geom_mosaic_text(aes(x = product(happy, health)), na.rm = TRUE)
# avoid overlapping text
ggplot(data = happy) +
geom_mosaic(aes(x = product(health), fill = happy), na.rm = TRUE, show.legend = FALSE) +
geom_mosaic_text(aes(x = product(happy, health)), na.rm = TRUE, check_overlap = TRUE)
# or use ggrepel
ggplot(data = happy) +
geom_mosaic(aes(x = product(health), fill = happy), na.rm = TRUE, show.legend = FALSE) +
geom_mosaic_text(aes(x = product(happy, health)), na.rm = TRUE, repel = TRUE)
# and as a label
ggplot(data = happy) +
geom_mosaic(aes(x = product(health), fill = happy), na.rm = TRUE, show.legend = FALSE) +
geom_mosaic_text(aes(x = product(happy, health)), na.rm = TRUE, repel = TRUE, as.label=TRUE)
# }
Run the code above in your browser using DataLab