Skip to contents

Visualizes the combined effect of two variables from a "mid" object using a 3D perspective plot.

Usage

# S3 method for class 'mid'
persp(x, pair, ..., resolution = c(50L, 50L))

Arguments

x

a "mid" object, typically the result of midr::interpret().

pair

a character string or a character vector of length two specifying the variables to be plotted. pair = "x*y" plots the sum of the main effects and their interaction, pair = "x+y" plots the sum of the two main effects, and pair = "x:y" plots only the interaction effect. A character vector of length two (e.g., c("x", "y")) is treated as "x+y".

...

additional arguments passed on to graphics::persp().

resolution

an integer or vector of two integers specifying the resolution of the evaluation grid for the x and y axes. Defaults to c(50L, 50L).

Value

persp.mid() invisibly returns the viewing transformation matrix.

Details

This is an S3 method for the persp() generic that plots a sum of effects for a "mid" object. The plotted effects are inferred from the pair argument.

See also

Examples

mid <- midr::interpret(mpg ~ wt * hp + factor(am), data = mtcars, lambda = .5)
#> 'model' not passed: response variable in 'data' is used

# Plot the sum of the main effects and their interaction
persp(mid, pair = "wt*hp", theta = 210, phi = 20)


# Plot only the interaction effect
persp(mid, pair = "wt:hp", theta = 210, phi = 20)


# Plot the additive main effects with a higher resolution
persp(mid, pair = "wt+hp", resolution = 100L, theta = 210, phi = 20)