inst/doc/rAppendixShowbox3mosaic.r

# A. Understand data; library(vcd) has more options for mosaic plots
setwd("C:/aErer")
Titanic; as.data.frame(Titanic)
str(Titanic)
ftable(Titanic)

# B. Draw a mosaic plot for two categorical variables
windows(width = 5.3, height = 2.5, pointsize = 9)
bringToTop(stay = TRUE)
par(mai = c(0.4, 0.4, 0.1, 0))
mosaicplot(formula = ~ Class + Survived, data = Titanic, 
  color = c("red", "green"), main = "", cex.axis = 1)
showMosaic <- recordPlot()

# C. Save the graph on a file device
pdf(file = "fig_showMosaic.pdf", width = 5.3, height = 2.5)
replayPlot(showMosaic)
dev.off()

Try the erer package in your browser

Any scripts or data that you put into this service are public.

erer documentation built on April 18, 2022, 5:06 p.m.