mk_scatterplot: Create a function for making publishable ggplot2...

View source: R/mk_scatterplot.R

mk_scatterplotR Documentation

Create a function for making publishable ggplot2 scatterplots.

Description

mk_scatterplot takes a data frame as input and returns a function for making scatterplots with any continuous variables from the data frame on the x and y axes. When supplied a categorical colorby variable, the output function will produce scatterplots where the points are colored differently according to the levels of the colorby variable.

Usage

mk_scatterplot(df)

Arguments

df

A data frame.

Value

function(xvar, yvar, colorby = "1", alpha = 0.8, pt_size = 1, jitter = FALSE, add_cnt_to_legend = TRUE, legend_title = colorby, legend_pos = "right", font_size = 14)

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

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

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

  • alpha. A number between 0 and 1, transparency level of the point colors. Smaller value means more transparent. Default = 0.8.

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

  • jitter. Logical, jitter points if TRUE. Used when there're overlapping points. Default = FALSE.

  • 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_scatterplot.R

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