An implementation of Stata's marginsplot as an S3 generic function
# S3 method for margins
plot(
x,
pos = seq_along(marginal_effects(x, with_at = FALSE)),
which = colnames(marginal_effects(x, with_at = FALSE)),
labels = gsub("^dydx_", "", which),
horizontal = FALSE,
xlab = "",
ylab = "Average Marginal Effect",
level = 0.95,
pch = 21,
points.col = "black",
points.bg = "black",
las = 1,
cex = 1,
lwd = 2,
zeroline = TRUE,
zero.col = "gray",
...
)
The original “margins” object x
, invisibly.
An object of class “margins”, as returned by margins
.
A numeric vector specifying the x-positions of the estimates (or y-positions, if horizontal = TRUE
).
A character vector specifying which marginal effect estimate to plot. Default is all.
A character vector specifying the axis labels to use for the marginal effect estimates. Default is the variable names from x
.
A logical indicating whether to plot the estimates along the x-axis with vertical confidence intervals (the default), or along the y-axis with horizontal confidence intervals.
A character string specifying the x-axis (or y-axis, if horizontal = TRUE
) label.
A character string specifying the y-axis (or x-axis, if horizontal = TRUE
) label.
A numeric value between 0 and 1 indicating the confidence level to use when drawing error bars.
The point symbol to use for plotting marginal effect point estimates. See points
for details.
The point color to use for plotting marginal effect point estimates. See points
for details.
The point color to use for plotting marginal effect point estimates. See points
for details.
An integer value specifying the orientation of the axis labels. See par
for details.
A numerical value giving the amount by which plotting text and symbols should be magnified relative to the default. See par
for details.
A numerical value giving the width of error bars in points.
A logical indicating whether to draw a line indicating zero. Default is TRUE
.
A character string indicating a color to use for the zero line if zeroline = TRUE
.
Additional arguments passed to plot.default
, such as title
, etc.
This function is invoked for its side effect: a basic dot plot with error bars displaying marginal effects as generated by margins
, in the style of Stata's marginsplot command.
margins
, persp.lm
if (FALSE) {
require("datasets")
x <- lm(mpg ~ cyl * hp + wt, data = mtcars)
mar <- margins(x)
plot(mar)
}
Run the code above in your browser using DataLab