The following table contains the count the number of Titanic survivals based of their economic status (class). This data will be used in the examples below.
# Data dat <- apply(Titanic, c(1, 4), sum)
|class \ Survived||No||Yes|
Spineplots are a generalization of stacked bar charts. The
spineplot function allows creating this type of graph in base R (actually a mosaic plot, which is a spineplot for two or more variables). See
?spineplot to know more about the possible input options.
Transpose the variables
The spineplot can be flipped transposing the data, as in the example below.
You can pass a vector of colors to
col to customize the default gray scale colors. Pass as many colors as classes on the Y-axis.
spineplot(dat, col = c("#07798D", "#7BCB9F"))
You can also customize the border color with
border. In this example we are setting it to the fill color.
spineplot(dat, col = c("#07798D", "#7BCB9F"), border = c("#07798D", "#7BCB9F"))
Spinograms are a generalization of histograms. The default
spineplot function creates a spineplot, but setting
off = 0 a spinogram will be created, removing the offset between the bars.
spineplot(dat, off = 0)