type_barplot | R Documentation |
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).
type_barplot(
width = 5/6,
beside = FALSE,
center = FALSE,
FUN = NULL,
xlevels = NULL,
xaxlabels = NULL,
drop.zeros = FALSE
)
width |
numeric, optional vector of bar widths. (The distance between the midpoints of the bars is always 1.) |
beside |
logical. In case of a |
center |
logical or numeric. In case of stacked barplots ( |
FUN |
a function to compute the summary statistic for |
xlevels |
a character or numeric vector specifying in which order the
levels of the |
xaxlabels |
a character vector with the axis labels for the |
drop.zeros |
logical. Should bars with zero height be dropped? If set
to |
# 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 = 0.65))
tinytheme("clean2")
# Example for numeric y aggregated by x (default: FUN = mean) + facets
tinyplot(extra ~ ID | group, facet = "by", data = sleep,
type = "barplot", 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)
# Centered barplot for conditional proportions of hair color (black/brown vs.
# red/blond) given eye color and sex
tinytheme("clean2", palette.qualitative = c("black", "sienna", "indianred", "goldenrod"))
hec = as.data.frame(proportions(HairEyeColor, 2:3))
tinyplot(Freq ~ Eye | Hair, facet = ~ Sex, data = hec, type = "barplot",
center = TRUE, flip = TRUE, facet.args = list(ncol = 1), yaxl = "percent")
tinytheme()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.