Description Usage Arguments Details Examples
This is a very thin wrapper around ggplot2 for creating bar charts, mainly because I find it difficult to remember stat= identity", position="dodge" and otherpreferences.
1 | grouped_barchart(mydf, xcolnum, ycolnum, fillcolnum, mytitle = "")
|
mydf |
A data frame |
xcolnum |
integer Data frame column number you want on the x axis |
ycolnum |
integer Data frame column you want on the y axis |
fillcolnum |
integer Data frame column you want bars colored by |
mytitle |
character string optional headline for graph |
Graph format from the R Graphics Cookbook by Winston Chang. Idea for using ggplot2 within another function from StackOverflow http://stackoverflow.com/a/27462105/718150
1 2 3 4 5 6 7 8 | # Initial graph from R Cookbook
# http://www.cookbook-r.com/Graphs/Bar_and_line_graphs_(ggplot2)/
dat1 <- data.frame(
sex = factor(c("Female","Female","Male","Male")),
time = factor(c("Lunch","Dinner","Lunch","Dinner"), levels=c("Lunch","Dinner")),
total_bill = c(13.53, 16.81, 16.24, 17.42)
)
grouped_barchart(dat1, 2, 3, 1, "Test graph")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.