# "spineplot" type convenience string
tinyplot(Species ~ Sepal.Width, data = iris, type = "spineplot")
# Aside: specifying the type is redundant for this example, since tinyplot()
# defaults to "spineplot" if y is a factor (just like base plot).
tinyplot(Species ~ Sepal.Width, data = iris)
# Use `type_spineplot()` to pass extra arguments for customization
tinyplot(Species ~ Sepal.Width, data = iris, type = type_spineplot(breaks = 4))
p = palette.colors(3, "Pastel 1")
tinyplot(Species ~ Sepal.Width, data = iris, type = type_spineplot(breaks = 4, col = p))
rm(p)
# More idiomatic tinyplot way of drawing the previous plot: use y == by
tinyplot(
Species ~ Sepal.Width | Species, data = iris, type = type_spineplot(breaks = 4),
palette = "Pastel 1", legend = FALSE
)
# Grouped and faceted spineplots
ttnc = as.data.frame(Titanic)
tinyplot(
Survived ~ Sex, facet = ~ Class, data = ttnc,
type = type_spineplot(weights = ttnc$Freq)
)
# For grouped "by" spineplots, it's better visually to facet as well
tinyplot(
Survived ~ Sex | Class, facet = "by", data = ttnc,
type = type_spineplot(weights = ttnc$Freq)
)
# Fancier version. Note the smart inheritance of spacing etc.
tinyplot(
Survived ~ Sex | Class, facet = "by", data = ttnc,
type = type_spineplot(weights = ttnc$Freq),
palette = "Dark 2", facet.args = list(nrow = 1), axes = "t"
)
# Note: It's possible to use "by" on its own (without faceting), but the
# overlaid result isn't great. We will likely overhaul this behaviour in a
# future version of tinyplot...
tinyplot(Survived ~ Sex | Class, data = ttnc,
type = type_spineplot(weights = ttnc$Freq), alpha = 0.3
)
Run the code above in your browser using DataLab