ConditionalSmoothedScatterPlot {WVPlots}R Documentation

Plot a scatter plot with smoothing line.

Description

Plot a scatter plot with a smoothing line; the smoothing window is aligned either left, center or right.

Usage

ConditionalSmoothedScatterPlot(
  frame,
  xvar,
  yvar,
  groupvar = NULL,
  title = "ConditionalSmoothedScatterPlot",
  ...,
  k = 3,
  align = "center",
  point_color = "black",
  point_alpha = 0.2,
  smooth_color = "black",
  palette = "Dark2"
)

Arguments

frame

data frame to get values from

xvar

name of the independent column in frame. Assumed to be regularly spaced

yvar

name of the dependent (output or result to be modeled) column in frame

groupvar

name of the grouping column in frame. Can be NULL for an unconditional plot

title

title for plot

...

no unnamed argument, added to force named binding of later arguments.

k

width of smoothing window. Must be odd for a center-aligned plot. Defaults to 3

align

smoothing window alignment: 'center', 'left', or 'right'. Defaults to 'center'

point_color

color of points, when groupvar is NULL. Set to NULL to turn off points.

point_alpha

alpha/opaqueness of points.

smooth_color

color of smoothing line, when groupvar is NULL

palette

name of Brewer palette, when groupvar is non-NULL (can be NULL)

Details

xvar is the continuous independent variable and yvar is the dependent binary variable. Smoothing is by a square window of width k.

If palette is NULL, and groupvar is non-NULL, plot colors will be chosen from the default ggplot2 palette. Setting palette to NULL allows the user to choose a non-Brewer palette, for example with scale_fill_manual.

Examples


if (requireNamespace('data.table', quietly = TRUE)) {
	# don't multi-thread during CRAN checks
		data.table::setDTthreads(1)
}

y = c(1,2,3,4,5,10,15,18,20,25)
x = seq_len(length(y))
df = data.frame(x=x, y=y, group=x>5)
WVPlots::ConditionalSmoothedScatterPlot(df, "x", "y", NULL,
   title="left smooth, one group", align="left")
# WVPlots::ConditionalSmoothedScatterPlot(df, "x", "y", "group",
#    title="left smooth, two groups", align="left")


[Package WVPlots version 1.3.8 Index]