
Last chance! 50% off unlimited learning
Sale ends in
Create a bar plot from a data frame through ggplotly
make_barplot(
dt,
bars,
value = NULL,
break_bars_by = NULL,
up_to_n_bars = 20,
horizontal = FALSE,
sort_by_value = horizontal,
sort_decreasing = TRUE,
ggtheme = "minimal",
x_axis_label = NULL,
y_axis_label = NULL,
plot_palette = NULL,
plot_palette_generator = "plasma",
static = FALSE
)
data.frame containing the data to plot.
Name of the column containing the different groups.
Name of the columns to use as value on the y axis of the plot. If NULL (default), counts will be used.
Name of the categorical variable used to break each bar
Plot up to this number of bars. If there are more distinct values in 'bars', the function will summarise them into an 'Others' category. Default is 20.
Plot the bars horizontally. Default is FALSE.
Sort the bars by value. Default is FALSE unless horizontal is TRUE.
Sort the values decreasingly. Default is TRUE, but sort_by_value must also be TRUE.
ggplot2 theme function to apply. Default is ggplot2::theme_minimal.
Label for the x axis.
Label for the y axis.
Character vector of hex codes specifying the colors to use on the plot.
Palette from the viridis package used in case plot_palette is unspecified or insufficient for the number of colors required
If TRUE (or if the dataset is over 10,000 rows), the output will be static ggplot chart instead of an interactive ggplotly chart. Default is FALSE.
A plotly-ized version of a ggplot bar plot.
# 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