mk_lineplot: Create a function for making publishable ggplot2 line plots.

View source: R/mk_lineplot.R

mk_lineplotR Documentation

Create a function for making publishable ggplot2 line plots.

Description

mk_lineplot takes a data frame as input and returns a function for making lineplots with any continuous variables from the data frame on the y axis, and any continuous or categorical variables from the data frame on the x axis. The x variable often measures time, for example, years. When supplied a categorical colorby variable, the output function will produce lineplots where lines are colored differently according to the levels of the colorby variable.

Usage

mk_lineplot(df)

Arguments

df

A data frame.

Value

function(xvar, yvar, colorby = "1", xorder = "alphanumeric", is_y_pct = FALSE, pt_size = 1, linew = 0.7, add_cnt_to_legend = TRUE, legend_title = colorby, legend_pos = "right", font_size = 14)

  • xvar. String, name of a continuous or categorical variable for x-axis.

  • yvar. String, name of a continuous variable for y-axis.

  • colorby. String, name of a categorical variable for grouping and coloring the lines. Default = "1", meaning no such variable is supplied.

  • xorder. String, "alphanumeric", "ascend" or "descend". It specifies how categories are ordered on the x-axis. Default is "alphanumeric".

  • is_y_pct. logical, if TRUE, apply the percent format on y-axis. Default is FALSE, which means do not apply any special format to y-axis.

  • pt_size. Number, size of the points. Default = 1.

  • linew. Number, width of the line. Default = 0.7.

  • add_cnt_to_legend. Logical, when TRUE (default), it will show the number of non-missing records for each level in the colorby var.

  • legend_title. String, legend title. Default uses the name of the colorby variable.

  • legend_pos. String, legend position. Default = "right".

  • font_size. Overall font size. Default = 14. The font size of the axes and legend text is a fraction of this value.

Examples

inst/examples/ex-mk_lineplot.R

gmlang/ezplot documentation built on Sept. 18, 2022, 6:33 a.m.