Learn R Programming

daltoolbox (version 1.2.747)

plot_bar: Plot bar graph

Description

Draw a simple bar chart from a two‑column data.frame: first column as categories (x), second as values.

Usage

plot_bar(data, label_x = "", label_y = "", colors = NULL, alpha = 1)

Value

returns a ggplot2::ggplot graphic

Arguments

data

two‑column data.frame: category in the first column, numeric values in the second

label_x

x‑axis label

label_y

y‑axis label

colors

optional fill color (single value)

alpha

bar transparency (0–1)

Details

If colors is provided, a constant fill is used; otherwise ggplot2's default palette applies. alpha controls bar transparency. The first column is coerced to factor when needed.

Examples

Run this code
#summarizing iris dataset
data <- iris |> dplyr::group_by(Species) |>
dplyr::summarize(Sepal.Length=mean(Sepal.Length))
head(data)

# plotting data
grf <- plot_bar(data, colors="blue")
plot(grf)

Run the code above in your browser using DataLab