Description Usage Arguments Value Bugs Examples
Draws barplots.
1 |
data_frame |
A data frame |
x_var |
A factor |
y_var |
A numerical variable |
main_title |
A string, optional main title of the barplot |
bar_width |
A floating number, optional bar width |
x_title |
A string, optional title of the x-axis |
x_limits |
A vector of length 2, optional scale limits, e.g., c(4,10) |
x_breaks |
A vector, optional scale breaks, e.g., c(4, 6, 9) |
x_ticks |
Logical, FALSE switches off tick marks on the x-axis |
y_title |
A string, optional title of the y-axis |
y_limits |
A vector of length 2, optional scale limits, e.g., c(0, 1) |
y_breaks |
A vector, optional breaks, e.g., c(0.0, 0.5, 1.0) |
y_facet |
A formular, an optional grid for the y-variable controlled by y_facet e.g., "SCHOOL ~ ." to have the y-variable sliced horizontally by a school name variable, or ". ~ SCHOOL" to have the y-variable sliced vertically by a school name variable. Defaults to FALSE. |
label_vars |
An optional label for the bars , e.g, "percent(FREQ)" |
percentage |
logical, if TRUE assumes that y_var is a percentage |
fill_vars |
A factor, an optional variable by which to slice the x-variable, used for filling the bars |
fill_palette |
A vector of length equal to the number of categories of fill_vars, an optional colour palette, defaults to fill_brewer |
colour_vars |
A factor, an optional variable by which to slice the x-variable, usually equal to fill_vars, used for colouring the outside edge of the bars |
colour_palette |
A vector of length equal to the number of categories of colour_vars, an optional colour palette, usually equal to fill_palette, but can be used to highlight the bar borders, defaults to colour_breweR |
pos |
A position, an optional placement rule for the bars, defaults to "dodge" |
barplot_alpha |
A floating number between 0 and 1, an optional degree of transparency for the bars, default at 1 |
colour_title |
legend guide for scale_colour, setting a title activates the legend, requires colour_vars to be set, defaults to FALSE. |
fill_title |
legend guide for scale_fill, setting a title activates the legend, requires fill_vars to be set, default at FALSE. |
legend_labels |
a vector of labels for the legend, e.g, c("M\u0101ori", "Pakeh\u0101") |
legend_rev |
determines whether the order of the legend labels should be reversed |
flip |
Flips x-axis and y-axis if TRUE, defaults to FALSE |
a bar plot object
Guide colour and guide fill currently take the same arguments and can not be controlled individually.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ## Not run:
library(tidyverse)
iris.plot <- iris %>% group_by(Species) %>% summarize(Sepal.Length=mean(Sepal.Length))
#Simple bar plot
p <- plot_barplot(iris.plot,
x_var = "Species",
y_var = "Sepal.Length")
print(p)
#Same bar plot with fill by Species and border colour by Species reversed
p <- plot_barplot(iris.plot,
main_title="Sepal.Length by Species on the Iris Data Set",
x_var = "Species",
y_var = "Sepal.Length",
fill_title = "Species",
fill_vars = "Species",
colour_vars = "rev(Species)")
print(p)
#Same bar plot with a facet for Sepal.Width and a legend with a title
p <- plot_barplot(iris,
x_var = "Species",
y_var = "Sepal.Length",
fill_vars = "Species",
y_facet = "Sepal.Width ~ .",
fill_title = "Species",
flip = TRUE)
print(p)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.