View source: R/graph_boxplot.R
graph_boxplot | R Documentation |
graph_boxplot
takes as input a data.frame of numeric values and the
categories those values are in and creates boxplots of those data. Options
are included for type of graph to make and some aesthetics.
graph_boxplot(
DF,
category_column,
value_column,
facet1_column,
facet2_column,
graph_type = "boxplot",
include_errorbars = FALSE,
x_axis_label = NA,
y_axis_label = NA,
color_set = "default",
save_graph = NA,
fig_width = 6,
fig_height = 4
)
DF |
the data.frame you want to graph, unquoted |
category_column |
the name of the column with categorical data, unquoted |
value_column |
the name of the column with value data, unquoted |
facet1_column |
(optional) the name of a column by which you might break up your graph into small multiples, unquoted. Please see the example if you're uncertain what this does. |
facet2_column |
(optional) the name of a second column by which you might break up the graph into small multiples, unquoted. |
graph_type |
the type of graph to plot. Options:
|
include_errorbars |
TRUE or FALSE (default) on whether to include horizontal error bars on the whiskers |
x_axis_label |
optionally supply a character vector or an expression to use for the x axis label |
y_axis_label |
optionally supply a character vector or an expression to use for the y axis label |
color_set |
the set of colors to use. Options:
|
save_graph |
optionally save the output graph by supplying a file name in quotes here, e.g., "My conc time graph.png". If you leave off ".png", it will be saved as a png file, but if you specify a different file extension, it will be saved as that file format. Acceptable extensions are "eps", "ps", "jpeg", "jpg", "tiff", "png", "bmp", or "svg". Do not include any slashes, dollar signs, or periods in the file name. Leaving this as NA means the file will not be automatically saved to disk. |
fig_width |
figure width in inches; default is 6 |
fig_height |
figure height in inches; default is 4 |
a ggplot2 graph
AUCs <- data.frame(AgeGroup = rep(LETTERS[1:5], each = 100),
AUC = c(rnorm(n = 100, mean = 10000, sd = 5000),
rnorm(n = 100, mean = 15000, sd = 5000),
rnorm(n = 100, mean = 20000, sd = 5000),
rnorm(n = 100, mean = 30000, sd = 5000),
rnorm(n = 100, mean = 33000, sd = 5000)))
graph_boxplot(AUCs, category_column = AgeGroup, value_column = AUC)
graph_boxplot(AUCs, category_column = AgeGroup, value_column = AUC,
color_set = "rainbow")
graph_boxplot(AUCs, category_column = AgeGroup, value_column = AUC,
color_set = "blue-green", graph_type = "jittered points")
graph_boxplot(AUCs, category_column = AgeGroup, value_column = AUC,
color_set = "Tableau", graph_type = "jittered points, filled boxes")
# Adding a couple of example columns to use the "facet" options.
AUCs$Sex <- c("M", "F")
AUCs$Metabolizer <- sample(c("poor", "extensive"), 100, replace = TRUE)
graph_boxplot(AUCs, category_column = AgeGroup, value_column = AUC,
facet1_column = Sex,
color_set = "blue-green", graph_type = "jittered points")
graph_boxplot(AUCs, category_column = AgeGroup, value_column = AUC,
facet1_column = Sex, facet2_column = Metabolizer,
color_set = "blue-green", graph_type = "jittered points")
graph_boxplot(AUCs, category_column = AgeGroup, value_column = AUC,
graph_type = "jittered points, filled boxes")
# Saving the output
graph_boxplot(AUCs %>% filter(AgeGroup %in% c("A", "B")),
category_column = AgeGroup, value_column = AUC,
graph_type = "jittered points, filled boxes",
color_set = "Brewer set 2", include_errorbars = TRUE,
save_graph = "test boxplot.png")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.