percent_bar_plot: Create a Percent Bar Plot

View source: R/percent_bar.R

percent_bar_plotR Documentation

Create a Percent Bar Plot

Description

Generates a bar plot visualizing the percentage distribution of a variable grouped by another variable.

Usage

percent_bar_plot(
  input,
  x,
  y,
  subset.x = NULL,
  color = NULL,
  palette = NULL,
  title = NULL,
  axis_angle = 0,
  coord_flip = FALSE,
  add_Freq = TRUE,
  Freq = "Proportion",
  size_freq = 8,
  legend.size = 0.5,
  legend.size.text = 10,
  add_sum = TRUE,
  print_result = TRUE,
  round.num = 2
)

Arguments

input

Input data frame.

x

Name of the x-axis variable.

y

Name of the y-axis (grouping) variable.

subset.x

Optional subset of x-axis values.

color

Optional color palette.

palette

Optional palette type.

title

Optional plot title.

axis_angle

Angle for axis labels (0-90). Default is 0.

coord_flip

Logical to flip coordinates. Default is FALSE.

add_Freq

Logical to add frequency count. Default is TRUE.

Freq

Name of frequency column.

size_freq

Size of frequency labels. Default is 8.

legend.size

Size of legend. Default is 0.5.

legend.size.text

Size of legend text. Default is 10.

add_sum

Logical to add sum to x-axis labels. Default is TRUE.

print_result

Logical to print result data frame. Default is TRUE.

round.num

Decimal places for proportion. Default is 2.

Value

A ggplot object.

Author(s)

Dongqiang Zeng

Examples

# Simulate data
set.seed(123)
sim_data <- data.frame(
  Subtype = sample(c("EBV", "GS", "MSI", "CIN"), 100, replace = TRUE),
  Lauren = sample(c("Diffuse", "Intestinal", "Mixed"), 100, replace = TRUE)
)

# Create percent bar plot
p <- percent_bar_plot(
  input = sim_data, x = "Subtype", y = "Lauren",
  axis_angle = 60
)
if (!is.null(p)) print(p)

IOBR documentation built on May 30, 2026, 5:07 p.m.