e_plot_scatterplot: Plot scatterplot of a numeric y-variable against a numeric or...

View source: R/e_plot_scatterplot.R

e_plot_scatterplotR Documentation

Plot scatterplot of a numeric y-variable against a numeric or categorical x-variable

Description

Can add up to one color factor or numeric variable and two facets factor variables, and choose to display correlation.

Usage

e_plot_scatterplot(
  dat_plot = NULL,
  var_x = NULL,
  var_y = NULL,
  var_color = NULL,
  var_facet = NULL,
  text_title = NULL,
  sw_print = FALSE,
  smooth_all = c("none", "loess", "lm", "glm", "gam")[1],
  sw_smooth_all_se = c(TRUE, FALSE)[1],
  smooth_by_var_color = c("none", "loess", "lm", "glm", "gam")[1],
  sw_smooth_by_var_color_se = c(TRUE, FALSE)[1],
  sw_corr_in_subtitle = c(TRUE, FALSE)[1]
)

Arguments

dat_plot

data to plot

var_x

a numeric or categorical variable name

var_y

a numeric variable name

var_color

factor or numeric color variable

var_facet

factor varibles (1 or 2) to facet by, (row facets, then column facets),

text_title

text for title of plot to override default

sw_print

T/F whether to print table and display plot

smooth_all

Smooth method for all the points together.

sw_smooth_all_se

T/F, SEs for smooth all the points together?

smooth_by_var_color

Smooth method by the color variable.

sw_smooth_by_var_color_se

T/F, SEs for smooth by the color variable?

sw_corr_in_subtitle

T/F, calculate correlation and include in subtitle of plot?

Value

     a ggplot object

Examples

e_plot_scatterplot(
    dat_plot  = dat_mtcars_e
  , var_x     = "disp"           # numeric x
  , var_y     = "mpg"
  )
e_plot_scatterplot(
    dat_plot  = dat_mtcars_e
  , var_x     = "am"             # factor x
  , var_y     = "mpg"
  )
e_plot_scatterplot(
    dat_plot  = dat_mtcars_e
  , var_x     = "disp"
  , var_y     = "mpg"
  , var_color = "cyl"            # factor color
  )
e_plot_scatterplot(
    dat_plot  = dat_mtcars_e
  , var_x     = "disp"
  , var_y     = "mpg"
  , var_color = "cyl"            # factor color
  , smooth_all = c("none", "loess", "lm", "glm", "gam")[2]  # with all smooth
  )
e_plot_scatterplot(
    dat_plot  = dat_mtcars_e
  , var_x     = "disp"
  , var_y     = "mpg"
  , var_color = "cyl"            # factor color
  , smooth_by_var_color = c("none", "loess", "lm", "glm", "gam")[3]  # with group smooth
  )
e_plot_scatterplot(
    dat_plot  = dat_mtcars_e
  , var_x     = "disp"
  , var_y     = "mpg"
  , var_color = "wt"             # numeric color
  )
e_plot_scatterplot(
    dat_plot  = dat_mtcars_e
  , var_x     = "disp"
  , var_y     = "mpg"
  , var_facet = c("vs")          # one facet
  )
e_plot_scatterplot(
    dat_plot  = dat_mtcars_e
  , var_x     = "disp"
  , var_y     = "mpg"
  , var_color = "cyl"
  , var_facet = c("vs", "am")    # two facets
  )
e_plot_scatterplot(
    dat_plot  = dat_mtcars_e
  , var_x     = "am"             # factor x
  , var_y     = "mpg"
  , var_color = "wt"             # numeric color
  , var_facet = c("vs")
  )
e_plot_scatterplot(
    dat_plot  = dat_mtcars_e
  , var_x     = "am"             # factor x
  , var_y     = "mpg"
  , var_color = "vs"             # factor color
  )

erikerhardt/erikmisc documentation built on April 17, 2025, 10:48 a.m.