plot_x: Plot a default scatterplot and add simple slope regression...

Description Usage Arguments See Also

View source: R/fun_utils.R

Description

This function may help to understand and interpret interaction effects observed in a linear model (lm) by means of simple slopes.

Usage

1
2
3
4
5
6
7
plot_x(data, model, y, x, xq = NULL, lvl = NULL, N = NULL, ylab = y,
  xlab = x[1], lwd = 2, lty = 1, col = "black", pch = 20,
  alpha = 0.05, col.s = NULL, xlim = range(data[, x[1]]),
  ylim = range(data[, y]), seg.len = 0.5, cex.legend = 0.8,
  plot.legend = TRUE, at.x = NULL, at.y = NULL, labels.x = TRUE,
  labels.y = TRUE, cex.x.axis = 1, cex.y.axis = 1, grid = TRUE,
  grid.h = NULL, padj.x = NA, padj.y = NA)

Arguments

data

A data frame, the same one that was used to fit the model.

model

An object of class (lm). Make sure to use the data argument of lm (i.e., do not use something like lm(d$y ~ d$x1*d$x2)).

y

Character. The dependent variable in the model.

x

Character vector. The independent variable(s) in the model for which the interaction effects should be plotted. If this is of length > 1, the first element will be used as the x-variable of the plot and the second element will be used for different simple slopes (and the third variable will be used for different plot panels).

xq

Character. Optional term in your model, namely, the quadratic effect of your first independent variable.

lvl

List of numeric vectors. The list must be of length 1 with two predictors and of length 2 with three predictors. Each vector contains the values of the corresponding predictor at which the plot is to be drawn. Defaults to three values, namely M - 1SD, M, and M + 1SD.

N

Numeric. A number of data points to plot; possibly smaller than nrow(data).

ylab

Y axis label, same font attributes as xlab.

xlab

X axis label using font and character expansion par("font.lab") and color par("col.lab").

lwd

Numeric. The line width(s) for the line(s) (see par).

lty

Numeric. The line type(s) for the line(s) (see par).

col

Character. The color of the points.

pch

the plotting symbols appearing in the legend, as numeric vector or a vector of 1-character strings (see points). Unlike points, this can all be specified as a single multi-character string. Must be specified for symbol drawing.

alpha

Numeric. An alpha transparency value (as an opacity, so 0 means fully transparent and 1 means opaque; see rgb).

col.s

Character vector. The color(s) of the slope(s). Must be of length 1 for one predictor and equal to length(lvl[[1]]) for 2 predictors.

xlim, ylim

Numeric vectors of length 2, giving the x and y coordinates ranges.

seg.len

the length of lines drawn to illustrate lty and/or lwd (in units of character widths).

cex.legend

Numeric. A value giving the amount by which the legend should be magnified (see par).

plot.legend

Logical. Should a legend be plotted.

at.x, at.y

Numeric. The points at which tick-marks for the x- and the y-axis, respectively, are to be drawn (see axis).

labels.x, labels.y

This can either be a logical value specifying whether (numerical) annotations are to be made at the tickmarks of the x- and y-axsi, respetively, or a character or expression vector of labels to be placed at the tickpoints. If this is not logical, at.x and/or at.y should also be supplied and of the same length (see axis).

cex.x.axis, cex.y.axis

The magnification to be used for axis annotation relative to the current setting of cex (see par).

grid

Logical. Should a grid be plotted.

grid.h

Numeric. Values of the y-axis at which the horizontal grid lines should be plotted.

padj.x, padj.y

Numeric. Adjustment for each tick label perpendicular to the reading direction. For labels parallel to the axes, padj = 0 means right or top alignment, and padj = 1 means left or bottom alignment (see axis).

See Also

par, plot, and legend


hplieninger/stylesim documentation built on May 17, 2019, 4:54 p.m.