View source: R/bcat_plt_area.R
| bcat_plt_area | R Documentation |
Create an area plot using ggplot2 graphics. This function is a wrapper to create commonly used styles of area plots. Additional layers can be added to this plot as needed. More complicated plots can be creating using individual ggplot2 layers.
bcat_plt_area(
df,
x = NULL,
y = NULL,
fill = NULL,
facet = NULL,
position = c("stack", "fill"),
x_lab = ggplot2::waiver(),
y_lab = ggplot2::waiver(),
title = ggplot2::waiver(),
subtitle = ggplot2::waiver(),
caption = ggplot2::waiver(),
legend_lab = ggplot2::waiver(),
legend_position = "right",
legend_hide = FALSE,
x_scale = NULL,
y_scale = NULL,
fill_scale = Rbearcat::scale_fill_UC(),
facet_scale = c("fixed", "free_y", "free_x", "free"),
nrow = NULL,
ncol = NULL,
x_refline = NULL,
y_refline = NULL
)
df |
The data to be displayed |
x |
variable to map to the x-axis |
y |
Variable to map to the y-axis |
fill |
Variable to map to the fill aesthetic |
facet |
Facetting variable(s). Note: must wrap in |
position |
Either stack values in cumulative fashion ( |
x_lab |
Label for x-axis |
y_lab |
Label for y-axis |
title |
Plot title |
subtitle |
Plot subtitle |
caption |
Plot caption |
legend_lab |
Legend title |
legend_position |
legend position. "bottom" or "right" |
legend_hide |
Set to |
x_scale |
|
y_scale |
|
fill_scale |
|
facet_scale |
Shoud facet scales be fixed ("fixed", the default), free ("free"), or free in one dimension ("free_x", "free_y") |
nrow |
Number of facet rows |
ncol |
Number of facet columns |
x_refline |
Vector of x-values at which to draw vertical reference lines |
y_refline |
Vector of y-values at which to draw horizontal reference lines |
A ggplot2 plot object.
Saannidhya Rawat
Other plots:
bcat_plt_bar(),
bcat_plt_box(),
bcat_plt_coef(),
bcat_plt_diag(),
bcat_plt_hist(),
bcat_plt_line(),
bcat_plt_point(),
bcat_plt_ts()
set.seed(1234)
d <- data.frame(t=rep(0:23,each=4),var=rep(LETTERS[1:4],4),val=round(runif(4*24,0,50)))
# stacked area plot
bcat_plt_area(df = d, x = t, y = val, fill = var,
position = "stack",
fill_scale = ggplot2::scale_fill_viridis_d(),
legend_lab = NULL)
# filled area plot
bcat_plt_area(df = d, x = t, y = val, fill = var,
position = "fill",
fill_scale = ggplot2::scale_fill_viridis_d(),
legend_lab = NULL)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.