Last chance! 50% off unlimited learning
Sale ends in
This function creates frequency bar charts for each discrete feature.
plot_bar(data, with = NULL, maxcat = 50, order_bar = TRUE, title = NULL,
ggtheme = theme_gray(), theme_config = list())
input data
name of continuous feature to be summed. Default is NULL
, i.e., frequency.
maximum categories allowed for each feature. The default is 50. More information in 'Details' section.
logical, indicating if bars should be ordered.
plot title
complete ggplot2 themes. The default is theme_gray.
a list of configurations to be passed to theme.
If a discrete feature contains more categories than maxcat
specifies, it will not be passed to the plotting function.
To change default font family and size, you may pass base_size
and base_family
to ggtheme
options, e.g., ggtheme = theme_gray(base_size = 15, base_family = "serif")
theme_config
argument expects all inputs to be wrapped in a list object, e.g., to change the text color: theme_config = list("text" = element_text(color = "blue"))
# NOT RUN {
# Load diamonds dataset from ggplot2
library(ggplot2)
data("diamonds", package = "ggplot2")
# Plot bar charts for diamonds dataset
plot_bar(diamonds)
plot_bar(diamonds, maxcat = 5)
# Plot bar charts with `price` feature
plot_bar(diamonds, with = "price")
# Plot bar charts with preset ggplot2 themes
plot_bar(diamonds, ggtheme = theme_light())
plot_bar(diamonds, ggtheme = theme_minimal(base_size = 20))
# Plot bar charts with customized theme components
plot_bar(diamonds,
theme_config = list(
"plot.background" = element_rect(fill = "yellow"),
"aspect.ratio" = 1
))
# }
Run the code above in your browser using DataLab