Skip to contents

For "mid" objects, ggmid() visualizes a MID component function using the ggplot2 package.

Usage

ggmid(object, ...)

# S3 method for class 'mid'
ggmid(
  object,
  term,
  type = c("effect", "data", "compound"),
  theme = NULL,
  intercept = FALSE,
  main.effects = FALSE,
  data = NULL,
  jitter = 0.3,
  cells.count = c(100L, 100L),
  limits = c(NA, NA),
  ...
)

# S3 method for class 'mid'
autoplot(object, ...)

Arguments

object

a "mid" object to be visualized.

...

optional parameters to be passed to the main layer.

term

a character string specifying the component function to be plotted.

type

character string. The method for plotting the interaction effects.

theme

a character string specifying the color theme or any item that can be used to define "color.theme" object.

intercept

logical. If TRUE, the intercept is added to the MID values.

main.effects

logical. If TRUE, the main effects are included in the interaction plot.

data

a data.frame to be plotted with the corresponding MID values. If not passed, data is extracted from parent.env() based on the function call of the "mid" object.

jitter

a numeric value specifying the amount of jitter for points.

cells.count

an integer or integer-valued vector of length two, specifying the number of cells for the raster type interaction plot.

limits

NULL or a numeric vector of length two specifying the limits of the plotting scale. NAs are replaced by the minimum and/or maximum MID values.

Value

ggmid.mid() returns a "ggplot" object.

Details

The S3 method of ggmid() for "mid" objects creates a "ggplot" object that visualizes a MID component function. The main layer is drawn using geom_line() or geom_path() for a main effect of a quantitative variable, geom_col() for a main effect of a qualitative variable, and geom_raster() or geom_rect() for an interaction effect. For other methods of ggmid(), see help(ggmid.mid.importance), help(ggmid.mid.breakdown) or help(ggmid.mid.conditional).

Examples

data(diamonds, package = "ggplot2")
set.seed(42)
idx <- sample(nrow(diamonds), 1e4)
mid <- interpret(price ~ (carat + cut + color + clarity)^2, diamonds[idx, ])
#> 'model' not passed: response variable in 'data' is used
ggmid(mid, "carat")

ggmid(mid, "clarity")

ggmid(mid, "carat:clarity", main.effects = TRUE)

ggmid(mid, "clarity:color", type = "data", theme = "Mako", data = diamonds[idx, ])

ggmid(mid, "carat:color", type = "compound", data = diamonds[idx, ])