scattergram: Scattergram

View source: R/plot.R

scattergramR Documentation

Scattergram

Description

A scattergram plot with density curves along axes.

Usage

scattergram(
  x,
  y,
  g = NULL,
  col = NULL,
  ...,
  add = FALSE,
  xlim = NULL,
  ylim = NULL,
  axs = "i",
  heights = 0.25,
  main = NULL,
  legend = TRUE,
  args.legend = list()
)

Arguments

x, y, g

the x-, y-, and group variables

col

a vector of colors or integers for each unique value of g

...

additional arguments passed to plot (e.g., xlim, panel.first) or further to par

add

logical; if TRUE, plots will be added to an existing or multi-panel figure

xlim, ylim

the x- and y-axis limits

axs

the style(s) of axis interval calculation; see par

heights

for add = TRUE, the relative height of each density panel compared to the figure region

main

the main figure title

legend

logical; if TRUE, a group legend is drawn

args.legend

a named list of legend arguments to override defaults

Examples

with(mtcars, {
  scattergram(mpg, wt)
})

with(mtcars, {
  scattergram(mpg, wt, cyl, col = rainbow(3), pch = 16)
})

with(mtcars, {
  scattergram(
    mpg, wt, c('Four', 'Six', 'Eight')[cyl / 2 - 1],
    xlab = 'MPG', ylab = 'Weight', las = 1,
    panel.first = abline(lm(wt ~ mpg), col = 5, lwd = 3),
    panel.last = abline(v = c(20, 25))
  )
})


## to add multiple figures on a plot, use add = TRUE
sp <- split(mtcars, mtcars$am)
op <- par(mfrow = 1:2, mar = c(5, 5, 5, 4), oma = c(0, 0, 0, 2))
lapply(sp, function(d) {
  scattergram(d$mpg, d$wt, d$cyl, col = 1:3, add = TRUE)
})
par(op)


raredd/plotr documentation built on Nov. 19, 2023, 4:09 a.m.