Learn R Programming

SciencesPo (version 1.3.9)

bar.plot: Plot a barplot with ggplot2

Description

Plot a barplot with ggplot2.

Usage

bar.plot(data, x.var = NULL, y.var = NULL, group.var = NULL,
  group.colors = NULL, palette = NULL, stat = "identity", ...)

Arguments

data
The data frame.
x.var
The name of column containing x variable. Default value is NULL.
y.var
The name of column containing y variable.
group.var
The name of column containing group variable. This variable is used to color plot according to the group.
group.colors
The color of groups; group.colors should have the same length as groups.
palette
This can be also used to indicate group colors. In this case the parameter group.colors should be NULL.
stat
The statistical transformation to use on the data for this layer; default value is identity. To get a bar graph of counts, don't map a variable to y, and use stat="bin"
...
Other parameters passed on to ggplot2.customize function.

encoding

UTF-8

Examples

Run this code
if (interactive()) {
x = sample(10, 100, rep = TRUE)
y = stats::rnorm(100)
z = sample(letters[1:3],100, rep=TRUE)
dat = data.frame(x,y,z)

bar.plot(dat, 'x', 'y')
bar.plot(dat, 'x', 'y', group.var = 'z')
}

Run the code above in your browser using DataLab