| percent_bar_plot | R Documentation |
Generates a bar plot visualizing the percentage distribution of a variable grouped by another variable.
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
)
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. |
A ggplot object.
Dongqiang Zeng
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.