View source: R/all_functions.r
bar.plot | R Documentation |
A function for creating harmonized ggplot2 bar charts
bar.plot( parent.df, category.col = "TRTGRP", category.label = "Treatment Group", x.label = "", y.col = "GWHRT", y.label = "Percentage of Subjects", y.limits = c(0, 0.7), y.ticks = seq(0, 0.3, 0.05), bar.position = "dodge", category.palette = c("red", "blue"), text.size = 3, text.buffer = 0.05, killMissing = TRUE )
parent.df |
data.frame used by ggplot |
category.col |
data.frame column associated with categorical variable (bar.plot, box.plot, cdf.plot, dot.plot, km.plot) |
category.label |
passed to x-axis label |
x.label |
value gets passed to labs |
y.col |
parent.df column associated with response vairable |
y.label |
value gets passed to labs |
y.limits |
passed to scale_y_continuous |
y.ticks |
passed to scale_y_continuous |
bar.position |
passed to geom_bar (bar.plot) |
category.palette |
colors assoicated with categorical variable |
text.size |
value gets passed to geom_text |
text.buffer |
used by bar.plot to control text placement |
killMissing |
logical used by bar.plot |
A ggplot object is returned.
Greg Cicconetti
{ # Access dummy demography dataset data(demog.data) levels(demog.data$SEX) <- c("Female", "Male") # A ggplot object is returned p1 <- bar.plot(parent.df = demog.data, y.col = "SEX", x.label= "Gender", y.label = "Percentage of Subjects", category.col = "REGION", category.label = "Region", y.limits = c(0, 0.35), y.ticks = seq(0, 0.5, 0.05), bar.position= "dodge", category.palette = RColorBrewer::brewer.pal(n=5, name = "Dark2"), text.size =4, text.buffer=.025, killMissing = TRUE) print(p1) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.