Learn R Programming

DataExplorer (version 0.6.0)

plot_bar: Create bar charts for discrete features

Description

This function creates frequency bar charts for each discrete feature.

Usage

plot_bar(data, with = NULL, maxcat = 50, order_bar = TRUE, title = NULL,
  ggtheme = theme_gray(), theme_config = list())

Arguments

data

input data

with

name of continuous feature to be summed. Default is NULL, i.e., frequency.

maxcat

maximum categories allowed for each feature. The default is 50. More information in 'Details' section.

order_bar

logical, indicating if bars should be ordered.

title

plot title

ggtheme

complete ggplot2 themes. The default is theme_gray.

theme_config

a list of configurations to be passed to theme.

Details

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"))

Examples

Run this code
# 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