View source: R/generic_barplot.R
generic_barplot | R Documentation |
This function generates a barplot using ggplot, providing flexibility in customising the plot according to your data. The barplot can represent different groups and sub-groups, with the option to calculate bar heights based on counts or specific values.
generic_barplot(
data,
group_by,
values_in = NULL,
fill_by = NULL,
percentaged = FALSE,
reverse = FALSE,
args_geom_bar = list()
)
data |
A data frame containing the data for plotting. |
group_by |
The name of the column in |
values_in |
(Optional) The name of the column in |
fill_by |
(Optional) The name of the column in |
percentaged |
If set to |
reverse |
Whether or not to reverse the stack order, passed to
|
args_geom_bar |
(Optional) List of arguments that are to be passed to
|
Note: This description was written by the help of ChatGPT.
A barplot visualising the data using ggplot.
# Basic usage
my_data <- data.frame(
group = c("A", "A", "A", "B", "B", "C", "C"),
value = c(10, 15, 3, 8, 12, 5, 20),
subgroup = c("X", "Y", "X", "X", "Y", "X", "Y")
)
generic_barplot(
data = my_data,
group_by = "group",
values_in = "value",
fill_by = "subgroup"
)
# Percentage-based bar heights
generic_barplot(
data = my_data,
group_by = "group",
values_in = "value",
fill_by = "subgroup",
percentaged = TRUE
)
# Pass arguments to geom_bar()
generic_barplot(
data = my_data,
group_by = "group",
args_geom_bar = list(fill = "red", width = 0.5)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.