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 my preferences.
1 2 | basic_barchart(mydf, xcolnum, ycolnum, mytitle = "", barlabels = FALSE,
outline = FALSE, orderby = 0, descending = FALSE)
|
mydf |
A data frame |
xcolnum |
integer Data frame column number you want on the x axis |
mytitle |
character string Optional headline for graph |
barlabels |
Boolean Optional if you want white labels on the bars showing values |
outline |
Boolean Optional if you want a black outline around the bars |
orderby |
integer Optional if you want x axis reordered by value of a column number |
descending |
Boolean Optional if you are ordering and want order to be descending, set to TRUE |
mycolnum |
integer Data frame column you want on the y axis |
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 | # Initial graph from R Cookbook
# http://www.cookbook-r.com/Graphs/Bar_and_line_graphs_(ggplot2)/
testdata <- data.frame(State = c("Arizona", "Colorado", "Florida", "Georgia",
"Idaho", "Nevada", "North Carolina", "South Carolina", "Texas", "Utah"), Change = c(24.6, 16.9, 17.6, 18.3, 21.1, 35.1, 18.5, 15.3, 20.6, 23.8))
basic_barchart(testdata, 1, 2, "Test graph", barlabels=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.