ggmid | R Documentation |
ggmid()
is an S3 generic function for creating various visualizations from MID-related objects using ggplot2.
For "mid" objects (i.e., fitted MID models), it visualizes a single component function specified by the term
argument.
ggmid(object, ...)
## S3 method for class 'mid'
ggmid(
object,
term,
type = c("effect", "data", "compound"),
theme = NULL,
intercept = FALSE,
main.effects = FALSE,
data = NULL,
limits = c(NA, NA),
jitter = 0.3,
resolution = c(100L, 100L),
...
)
## S3 method for class 'mid'
autoplot(object, ...)
object |
a "mid" object to be visualized. |
... |
optional parameters passed to the main plotting layer. |
term |
a character string specifying the component function to be plotted. |
type |
the plotting style. One of "effect", "data" or "compound". |
theme |
a character string or object defining the color theme. See |
intercept |
logical. If |
main.effects |
logical. If |
data |
a data frame to be plotted with the corresponding MID values. If not provided, data is automatically extracted based on the function call. |
limits |
a numeric vector of length two specifying the limits of the plotting scale. |
jitter |
a numeric value specifying the amount of jitter for the data points. |
resolution |
an integer or vector of two integers specifying the resolution of the raster plot for interactions. |
For "mid" objects, ggmid()
creates a "ggplot" object that visualizes a component function of the fitted MID model.
The type
argument controls the visualization style.
The default, type = "effect"
, plots the component function itself.
In this style, the plotting method is automatically selected based on the effect's type:
a line plot for quantitative main effects; a bar plot for qualitative main effects; and a raster plot for interactions.
The type = "data"
option creates a scatter plot of data
, colored by the values of the component function.
The type = "compound"
option combines both approaches, plotting the component function alongside the data points.
ggmid.mid()
returns a "ggplot" object.
interpret
, ggmid.mid.importance
, ggmid.mid.conditional
, ggmid.mid.breakdown
, plot.mid
data(diamonds, package = "ggplot2")
set.seed(42)
idx <- sample(nrow(diamonds), 1e4)
mid <- interpret(price ~ (carat + cut + color + clarity)^2, diamonds[idx, ])
# Plot a quantitative main effect
ggmid(mid, "carat")
# Plot a qualitative main effect
ggmid(mid, "clarity")
# Plot an interaction effect with data points and a raster layer
ggmid(mid, "carat:clarity", type = "compound", data = diamonds[idx, ])
# Use a different color theme
ggmid(mid, "clarity:color", theme = "RdBu")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.