Generic function plotting for R objects. Currently plots exist for
data.frame
s, lm
s, (including glm
s).
mplot(object, ...)
# S3 method for default
mplot(object, ...)
# S3 method for lm
mplot(
object,
which = c(1:3, 7),
system = c("ggplot2", "lattice", "base"),
ask = FALSE,
multiplot = "package:gridExtra" %in% search(),
par.settings = theme.mosaic(),
level = 0.95,
title = paste("model: ", deparse(object$call), "\n"),
rows = TRUE,
id.n = 3L,
id.size = 5,
id.color = "red",
id.nudge = 1,
add.smooth = TRUE,
smooth.color = "red",
smooth.alpha = 0.6,
smooth.size = 0.7,
span = 3/4,
...
)
# S3 method for data.frame
mplot(
object,
format,
default = format,
system = c("ggformula", "ggplot2", "lattice"),
show = FALSE,
data_text = rlang::expr_deparse(substitute(object)),
title = "",
...
)
# S3 method for summary.lm
mplot(
object,
system = c("ggplot2", "lattice"),
level = 0.95,
par.settings = trellis.par.get(),
rows = TRUE,
...
)
# S3 method for TukeyHSD
mplot(
object,
system = c("ggplot2", "lattice"),
ylab = "",
xlab = "difference in means",
title = paste0(attr(object, "conf.level") * 100, "% family-wise confidence level"),
par.settings = trellis.par.get(),
order = c("asis", "pval", "difference"),
...
)
an R object from which a plot will be constructed.
additional arguments. If object
is an lm
, subsets
of these arguments are passed to gridExtra::grid.arrange
and to the
lattice plotting routines; in particular,
nrow
and ncol
can be used to control the number of rows
and columns used.
a numeric vector used to select from 7 potential plots
which graphics system to use (initially) for plotting (ggplot2 or lattice). A check box will allow on the fly change of plotting system.
if TRUE, each plot will be displayed separately after the user responds to a prompt.
if TRUE and ask == FALSE
, all plots will be
displayed together.
lattice theme settings
a confidence level
title for plot
rows to show. This may be a numeric vector,
TRUE
(for all rows), or a character vector of row names.
Number of id labels to display.
Size of id labels.
Color of id labels.
a numeric used to increase (>1) or decrease (<1) the amount that observation labels are nudged. Use a negative value to nudge down instead of up.
A logicial indicating whether a LOESS smooth should be added (where this makes sense to do). Currently ignored for lattice plots.
Color, size, and alpha used for LOESS curve. Currently ignored for lattice plots.
A positive number indicating the amount of smoothing.
A larger number indicates more smoothing. See stats::loess()
for details.
Currently ignored for lattice plots.
default type of plot to create; one of
"scatter"
,
"jitter"
,
"boxplot"
,
"violin"
,
"histogram"
,
"density"
,
"frequency polygon"
,
or
"map"
.
Unique prefixes suffice.
a logical, if TRUE
, the code will be displayed each time the plot is
changed.
text representation of the data set. In typical use cases, the default value should suffice.
label for y-axis
label for x-axis
one of "pval"
, "diff"
, or "asis"
determining the
order of the pair
factor, which determines the order in which the differences
are displayed on the plot.
a data frame containing the variables that might be used in the plot.
Nothing. Just for side effects.
The method for models (lm and glm) is still a work in progress, but should be usable for
relatively simple models. When the results for a logistic regression model created with
glm()
are satisfactory will depend on the format and structure of the data
used to fit the model.
Due to a bug in RStudio 1.3, the method for data frames may not display the controls consistently. We have found that executing this code usually fixes the problem:
lm( width ~ length * sex, data = KidsFeet) |>
mplot(which = 1:3, id.n = 5)
lm( width ~ length * sex, data = KidsFeet) |>
mplot(smooth.color = "blue", smooth.size = 1.2, smooth.alpha = 0.3, id.size = 3)
lm(width ~ length * sex, data = KidsFeet) |>
mplot(rows = 2:3, which = 7)
if (FALSE) {
mplot( HELPrct )
mplot( HELPrct, "histogram" )
}
lm(width ~ length * sex, data = KidsFeet) |>
summary() |>
mplot()
lm(width ~ length * sex, data = KidsFeet) |>
summary() |>
mplot(rows = c("sex", "length"))
lm(width ~ length * sex, data = KidsFeet) |>
summary() |>
mplot(rows = TRUE)
lm(age ~ substance, data = HELPrct) |>
TukeyHSD() |>
mplot()
lm(age ~ substance, data = HELPrct) |>
TukeyHSD() |>
mplot(system = "lattice")