grouped_barchart: Create a grouped barchart from data frame

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 stat= identity", position="dodge" and otherpreferences.

Usage

1
grouped_barchart(mydf, xcolnum, ycolnum, fillcolnum, mytitle = "")

Arguments

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

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
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")

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