| plot_bar | R Documentation |
Create a bar chart for grouped numeric values.
plot_bar(
data,
x,
y,
position = "dodge",
facet_var = NULL,
facet_scale = "free",
facet_nrow = NULL,
facet_ncol = NULL,
color = NULL,
flip = FALSE,
reorder = FALSE,
title = NULL,
subtitle = NULL,
xlab = NULL,
ylab = NULL,
caption = NULL,
bar_size = 0.75,
bar_color = "grey35",
bar_alpha = 1,
theme_set = theme_tscv(),
theme_config = list(),
...
)
data |
A |
x |
Unquoted column in |
y |
Unquoted column in |
position |
Character value defining the bar position. Common values are
|
facet_var |
Optional unquoted column in |
facet_scale |
Character value defining facet axis scaling. Common values
are |
facet_nrow |
Optional integer. Number of rows in the facet layout. |
facet_ncol |
Optional integer. Number of columns in the facet layout. |
color |
Optional unquoted column in |
flip |
Logical value. If |
reorder |
Logical value. If |
title |
Character value. Plot title. |
subtitle |
Character value. Plot subtitle. |
xlab |
Character value. Label for the x-axis. |
ylab |
Character value. Label for the y-axis. |
caption |
Character value. Plot caption. |
bar_size |
Numeric value defining the bar border line width. |
bar_color |
Character value defining the bar fill color. Ignored when
|
bar_alpha |
Numeric value between |
theme_set |
A complete |
theme_config |
A named |
... |
Currently not used. |
plot_bar() is a convenience wrapper around ggplot2::geom_bar()
with stat = "identity". It is intended for data that already contains
summarized values, for example accuracy metrics, counts, or grouped summary
statistics.
The arguments x, y, facet_var, and color are
passed as unquoted column names.
If color is supplied, bar fill colors are mapped to that variable and
bar_color is ignored. If color is not supplied, all bars are
drawn using bar_color.
The argument position controls how bars are displayed when
color is supplied. Common values are "dodge" and
"stack".
If flip = TRUE, the x-axis and y-axis are swapped using
ggplot2::coord_flip().
If reorder = TRUE, tidytext::scale_x_reordered() is added.
This is useful when the x-axis has been reordered within facets with
tidytext::reorder_within().
Additional theme settings can be supplied through theme_config. This
should be a named list of arguments passed to ggplot2::theme().
An object of class ggplot.
Other data visualization:
plot_density(),
plot_histogram(),
plot_line(),
plot_point(),
plot_qq(),
scale_color_tscv(),
scale_fill_tscv(),
theme_tscv(),
tscv_cols(),
tscv_pal()
library(dplyr)
context <- list(
series_id = "series",
value_id = "value",
index_id = "index"
)
data <- M4_monthly_data |>
filter(series %in% c("M23100", "M14395"))
stats <- summarise_stats(
.data = data,
context = context
)
plot_bar(
data = stats,
x = series,
y = mean,
title = "Average Value by Series",
xlab = "Series",
ylab = "Mean"
)
acf_data <- estimate_acf(
.data = data,
context = context,
lag_max = 12
)
plot_bar(
data = acf_data,
x = lag,
y = value,
facet_var = series,
title = "Autocorrelation by Series",
subtitle = "Sample autocorrelation up to lag 12",
xlab = "Lag",
ylab = "ACF"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.