Learn R Programming

chronicle (version 0.1.0)

make_barplot: Create a bar plot from a data frame through ggplotly

Description

Create a bar plot from a data frame through ggplotly

Usage

make_barplot(
  dt,
  bars,
  value = NULL,
  break_bars_by = NULL,
  horizontal = FALSE,
  sort_by_value = FALSE,
  sort_decreasing = TRUE,
  ggtheme = "minimal",
  x_axis_label = NULL,
  y_axis_label = NULL,
  plot_palette = NULL,
  plot_palette_generator = "plasma"
)

Arguments

dt

data.frame containing the data to plot.

bars

Name of the column containing the different groups.

value

Name of the columns to use as value on the y axis of the plot. If NULL (default), counts will be used.

break_bars_by

Name of the categorical variable used to break each bar

horizontal

Plot the bars horizontally. Default is FALSE

sort_by_value

Sort the bars by value. Default is FALSE

sort_decreasing

Sort the values decreasingly. Default is TRUE, but sort_by_value must also be TRUE.

ggtheme

ggplot2 theme function to apply. Default is ggplot2::theme_minimal.

x_axis_label

Label for the x axis.

y_axis_label

Label for the y axis.

plot_palette

Character vector of hex codes specifying the colors to use on the plot.

plot_palette_generator

Palette from the viridis package used in case plot_palette is unspecified or insufficient for the number of colors required

Value

A plotly-ized version of a ggplot bar plot.

Examples

Run this code
# NOT RUN {
make_barplot(dt = iris, bars = 'Species', value = 'Sepal.Length')
make_barplot(dt = ggplot2::mpg,
             bars = 'manufacturer',
             break_bars_by = 'model',
             value = 'cty',
             horizontal = TRUE,
             sort_by_value = TRUE)
# }

Run the code above in your browser using DataLab