basic_barchart: Create a basic barchart from data frame with ggplot2

Description Usage Arguments Details Examples

Description

This is a very thin wrapper around ggplot2 for creating bar charts, mainly because I find it difficult to remember my preferences.

Usage

1
2
basic_barchart(mydf, xcolnum, ycolnum, mytitle = "", barlabels = FALSE,
  outline = FALSE, orderby = 0, descending = FALSE)

Arguments

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

Details

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

Examples

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)

smach/rvisutils documentation built on May 30, 2019, 3:06 a.m.