Type function for producing barplots. For formulas of type ~ x (without left-hand side) the barplot visualizes the counts (absolute frequencies) of the levels of x. For formulas of type y ~ x the value of y within each level of x is visualized, if necessary aggregated using some function (default: mean).
numeric, optional vector of bar widths. (The distance between the midpoints of the bars is always 1.)
beside
logical. In case of a by grouping variable, should bars be juxtaposed? Default is to use stacked bars instead.
FUN
a function to compute the summary statistic for y within each group of x in case of using a two-sided formula y ~ x (default: mean).
xlevels
a character or numeric vector specifying in which order the levels of the x variable should be plotted.
drop.zeros
logical. Should bars with zero height be dropped? If set to FALSE (default) a zero height bar is still drawn for which the border lines will still be visible.
Examples
library("tinyplot")# Basic examples of frequency tables (without y variable)tinyplot(~ cyl, data = mtcars, type ="barplot")
tinyplot(~ cyl | vs, data = mtcars, type ="barplot")
tinyplot(~ cyl | vs, data = mtcars, type ="barplot", beside =TRUE)
tinyplot(~ cyl | vs, data = mtcars, type ="barplot", beside =TRUE, fill =0.2)
# Note: Above we used automatic argument passing for `beside`. But this# wouldn't work for `width`, since it would conflict with the top-level# `tinyplot(..., width = <width>)` argument. It's safer to pass these args# through the `type_barplot()` functional equivalent.tinyplot(~ cyl | vs, data = mtcars, fill =0.2,type =type_barplot(beside =TRUE, drop.zeros =TRUE, width = .65))
tinytheme("clean2")# Example for numeric y aggregated by x (default: FUN = mean) + facetstinyplot(extra ~ ID | group, facet ="by", data = sleep,type ="barplot", beside =TRUE, fill =0.6)
# Fancy frequency table:tinyplot(Freq ~ Sex | Survived, facet =~ Class, data =as.data.frame(Titanic),type ="barplot", facet.args =list(nrow =1), flip =TRUE, fill =0.6)