Description Usage Arguments Details Value Author(s) Examples
Creates a bar plot with vertical or horizontal bars
1 2 3 4 5 6 7 8 | gg_barplot(data, var, var_levels = NULL, group = NULL,
group_levels = NULL, facet_r = NULL, facet_c = NULL,
facet_r_levels = NULL, facet_c_levels = NULL, facet_scale = "free",
facet_space = "free", x_lab = NULL, y_lab = NULL, group_lab = group,
title = NULL, add_counts = TRUE, counts_pos = "inside-bar",
bar_label_align = "left", bar_label_angle = NULL,
group_bar_position = "dodge", grids = "on", bw_theme = TRUE,
horizontal = TRUE)
|
data |
Data frame: default dataset to use for plot |
var |
Character: name of a |
var_levels |
Vector/List: a named vector/list that specifies the
levels and labels of |
group |
Character: name of a |
group_levels |
Vector/List: a named vector/list that specifies the
levels and labels of |
facet_r |
Character: name of a |
facet_c |
Character: name of a |
facet_r_levels |
Vector/List: a named vector/list that specifies the
levels and labels of |
facet_c_levels |
Vector/List: a named vector/list that specifies the
levels and labels of |
facet_scale |
Character: Are scales shared across all facets. Refer to
the 'scale' argument in |
facet_space |
Character: Refer to the 'space' argument in
|
x_lab |
Character: x-axis label |
y_lab |
Character: y-axis label |
group_lab |
Character: group variable label |
title |
Character: barplot title |
add_counts |
Logical: If 'TRUE' (default), counts will be added to the bars |
counts_pos |
Character: position to add counts. If 'inside-bar'
(default), counts will be inside the bars; if 'outside-bar', counts be
placed outside the bars. When |
bar_label_align |
Character: alignment of the bar labels. If 'left' (default), labels will be left-aligned; if 'center', labels will be center-aligned; if 'right', labels will be right-aligned |
bar_label_angle |
Numeric: the orientation angle (in [0, 360]) of the bar labels on the axis. By default, the label will be perpendicular to the axis |
group_bar_position |
Character: position adjustment for bars of same
group when |
grids |
Character: control the grids. If 'on' (default), grids will be drawn; if 'x', only grids on x-axis will be drawn; if 'y', only grids on y-axis will be drawn; if 'off', no grids will be drawn |
bw_theme |
Logical: If 'TRUE' (default), black-and-white theme will be
used. Refer to |
horizontal |
Logical: If 'TRUE' (default), horizontal barplot is drawn; if 'FALSE', vertical barplot is drawn |
This function relies on ggplot2 package to create a bar plot with vertical or horizontal bars. The function supports panel plot layout. Counts information can be added to the corresponding bars. By default black-and-white theme is used.
An object of class ggplot. Can be directly sent to plot with
print
Feiyang Niu (Feiyang.Niu@gilead.com)
1 2 3 4 5 6 | gg_barplot(mpg, var = 'class', x_lab = '', horizontal = FALSE)
gg_barplot(mpg, var = 'class', group = 'cyl', group_lab = 'Cylinders')
var_levels <- c('Mid-size' = 'midsize', 'Minivan' = 'minivan', 'SUV' = 'suv')
gg_barplot(mpg, var = 'class', var_levels = var_levels,
group = 'cyl', group_lab = 'Cylinders', add_counts = FALSE)
gg_barplot(mpg, var = 'class', group = 'cyl', group_bar_position = 'stack')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.