View source: R/bcat_plt_line.R
| bcat_plt_line | R Documentation |
Create a line plot using ggplot2 graphics. This function is a wrapper to create commonly used styles of line plots. Additional layers can be added to this plot as needed. More complicated plots can be creating using individual ggplot2 layers.
bcat_plt_line(
df,
x,
y,
color = NULL,
linetype = NULL,
facet = NULL,
x_lab = ggplot2::waiver(),
y_lab = ggplot2::waiver(),
title = ggplot2::waiver(),
subtitle = ggplot2::waiver(),
caption = ggplot2::waiver(),
legend_lab = ggplot2::waiver(),
legend_position = "bottom",
legend_hide = FALSE,
x_scale = NULL,
y_scale = NULL,
color_scale = Rbearcat::scale_colour_UC(),
facet_scale = c("fixed", "free_y", "free_x", "free"),
nrow = NULL,
ncol = NULL,
layer_points = FALSE,
x_refline = NULL,
y_refline = NULL,
x_highlight_min = NULL,
x_highlight_max = NULL,
y_highlight_min = NULL,
y_highlight_max = NULL,
y_ribbon_min = NULL,
y_ribbon_max = NULL,
y_error_min = NULL,
y_error_max = NULL,
y_error_width = 1
)
df |
The data to be displayed |
x |
Variable to map to the x-axis |
y |
Variable to map to the y-axis |
color |
Variable to map to the color aesthetic |
linetype |
Variable to map to the linetype aesthetic |
facet |
Facetting variable(s). Note: must wrap in |
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 |
|
color_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 |
layer_points |
Set to |
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 |
x_highlight_min |
Vector of min x-values at which to start draw rectangle annotation |
x_highlight_max |
Vector of max x-values at which to end rectangle annotation |
y_highlight_min |
Vector of min y-values at which to start draw rectangle annotation |
y_highlight_max |
Vector of max y-values at which to end rectangle annotation |
y_ribbon_min |
Variable to use as minimum values for ribbon around y at each value of x |
y_ribbon_max |
Variable to use as maximum values for ribbon around y at each value of x |
y_error_min |
Variable to use as minimum values for error bars around y at each value of x |
y_error_max |
Variable to use as maximum values for error bars around y at each value of x |
y_error_width |
Width of error bars |
A ggplot2 plot object.
Saannidhya Rawat
Other plots:
bcat_plt_area(),
bcat_plt_bar(),
bcat_plt_box(),
bcat_plt_coef(),
bcat_plt_diag(),
bcat_plt_hist(),
bcat_plt_point(),
bcat_plt_ts()
library(ggplot2)
library(scales)
# basic time series plot with a reference line
bcat_plt_line(df = economics,
x = date,
y = unemploy,
y_scale = scale_y_continuous(labels = comma_format()),
y_refline = 10000)
# line plot with facets and highlight periods
bcat_plt_line(df = economics_long,
x = date,
y = value,
color = variable,
facet = vars(variable),
x_lab = "Decade",
y_lab = "Value",
legend_lab = NULL,
facet_scale = "free_y",
x_highlight_min = as.Date(c("2000-01-01", "2008-01-01")),
x_highlight_max = as.Date(c("2002-01-01", "2010-01-01")),
ncol = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.