Standard line plot using ggplot2. Y-variable not necessary.
line_plot(
df,
x_var,
color_var = NULL,
y_var = NULL,
group_by_x_var = TRUE,
y_percent = TRUE,
percent_accuracy = 1,
y_lim = NULL,
y_breaks = 2000,
y_breaks_end = 1e+05,
line_size = 1,
title = NULL,
subtitle = NULL,
y_lab = NULL,
x_lab = NULL,
fill_colors = NULL,
legend_labels = ggplot2::waiver(),
label_breaks = ggplot2::waiver(),
legend_row = NULL,
legend_col = NULL,
expand = TRUE,
...
)
Data frame.
Variable for x-axis, use string name. Recommended that x_var is in character in df (not necessary).
Variable for the different colors in lines, use string
name. Use NULL
if only one color for lines.
Variable for y axis, if NULL
, count is used.
Boolean indicating if percentages should be for x_var
or color_var
.
If TRUE
, y-axis is in percent form. Otherwise in count
form.
Set accuracy for scales::percent_format()
.
Limit on y-axis.
Length between each break on y-axis.
Break end, default for 100,000. Works for all count values below that.
Size of the lines.
Plot title, NULL
if no title.
Small text under title, NULL
if no subtitle.
Y-axis label, use NULL
for no label.
X-axis label, use NULL
for no label.
Colors of the different categories in color_var.
Label for each legend key.
Order of the legend keys.
How many rows for the legends.
How many columns for the legends.
If TRUE
, the margins around the data are kept.
Arguments passed to theme_slr()
Ggplot object containing line-plot.
# Example data
df <- ggplot2::diamonds
# y_percent = TRUE
line_plot(df, 'cut', 'color', y_breaks = 2)
line_plot(df, 'cut', 'color', group_by_x_var = FALSE, y_breaks = 2)
# y_percent = FALSE
line_plot(df, 'cut', 'color', y_percent = FALSE, y_breaks = 2000)
# y variable included
df2 <- dplyr::group_by(df, color, cut) %>%
dplyr::summarise(y = dplyr::n(), .groups = "drop_last")
line_plot(df2, 'cut', 'color', y_var = 'y', y_percent = FALSE, y_breaks = 2000)
line_plot(df2[df2$color == 'D', ], 'cut', y_var = 'y', y_percent = FALSE,
y_breaks = 500)