mplot: Generic plotting

View source: R/mplot.R

mplotR Documentation

Generic plotting

Description

Generic function plotting for R objects. Currently plots exist for data.frames, lms, (including glms).

Usage

mplot(object, ...)

## Default S3 method:
mplot(object, ...)

## S3 method for class '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 class '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 class 'summary.lm'
mplot(
  object,
  system = c("ggplot2", "lattice"),
  level = 0.95,
  par.settings = trellis.par.get(),
  rows = TRUE,
  ...
)

## S3 method for class '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"),
  ...
)

Arguments

object

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.

which

a numeric vector used to select from 7 potential plots

system

which graphics system to use (initially) for plotting (ggplot2 or lattice). A check box will allow on the fly change of plotting system.

ask

if TRUE, each plot will be displayed separately after the user responds to a prompt.

multiplot

if TRUE and ask == FALSE, all plots will be displayed together.

par.settings

lattice theme settings

level

a confidence level

title

title for plot

rows

rows to show. This may be a numeric vector, TRUE (for all rows), or a character vector of row names.

id.n

Number of id labels to display.

id.size

Size of id labels.

id.color

Color of id labels.

id.nudge

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.

add.smooth

A logicial indicating whether a LOESS smooth should be added (where this makes sense to do). Currently ignored for lattice plots.

smooth.color, smooth.size, smooth.alpha

Color, size, and alpha used for LOESS curve. Currently ignored for lattice plots.

span

A positive number indicating the amount of smoothing. A larger number indicates more smoothing. See stats::loess() for details. Currently ignored for lattice plots.

format, default

default type of plot to create; one of "scatter", "jitter", "boxplot", "violin", "histogram", "density", "frequency polygon", or "map". Unique prefixes suffice.

show

a logical, if TRUE, the code will be displayed each time the plot is changed.

data_text

text representation of the data set. In typical use cases, the default value should suffice.

ylab

label for y-axis

xlab

label for x-axis

order

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.

data

a data frame containing the variables that might be used in the plot.

Details

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:

library(manipulate) 
manipulate(plot(A), A = slider(1, 10))

Value

Nothing. Just for side effects.

Examples

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)
## Not run: 
mplot( HELPrct )
mplot( HELPrct, "histogram" )

## End(Not run)
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")

ProjectMOSAIC/mosaic documentation built on Feb. 21, 2024, 2:11 a.m.