dsplot: Discrete scatter plot

View source: R/plot.R

dsplotR Documentation

Discrete scatter plot

Description

This creates a scatter plot (sort of) for discrete, bivariate data; an alternative to sunflower plots for integer-valued variables.

Usage

dsplot(x, ...)

## Default S3 method:
dsplot(
  x,
  y,
  ...,
  bg.col = TRUE,
  col = par("col"),
  xlab = NULL,
  ylab = NULL,
  pch = par("pch"),
  cex = par("cex")
)

## S3 method for class 'formula'
dsplot(formula, data = NULL, ..., subset, na.action = NULL)

Arguments

x, y

x- and y-axis variables

...

for the formula method, named arguments to be passed to the default method

for the default method, unnamed arguments are additional data vectors (unless x is a list when they are ignored), and named arguments are arguments and pars to be passed to plot

bg.col

logical or color name to fill boxes with based on density; if FALSE, gridlines are drawn to distinguish boxes; if TRUE, grayscale is used as the default color

col

plotting color

xlab, ylab

x- and y-axis labels

pch

plotting character

cex

numerical value giving the amount by which plotting text and symbols should be magnified relative to the default; this starts as 1 when a device is opened and is reset when the layout is changed, e.g., by setting mfrow

formula

a formula, such as y ~ group, where y is a numeric vector of data values to be split into groups according to the grouping variable group (usually a factor)

data

a data frame (or list) from which the variables in formula should be taken

subset

an optional vector specifying a subset of observations to be used for plotting

na.action

a function which indicates what should happen when the data contain NAs; the default is to ignore missing values in either the response or the group

Value

A table (invisibly) corresponding to the plot cell counts.

References

Tatsuki dsplot

Examples

set.seed(1)
x <- round(rnorm(400, 100, 4))
y <- round(rnorm(400, 200, 4))
sex <- sample(c('Female', 'Male'), 400, replace = TRUE)

dsplot(x, y, col = (sex %in% 'Female') + 1L, bg.col = FALSE)
dsplot(x, y, col = (sex %in% 'Female') + 1L, bg.col = 'tomato')

dsplot(y ~ x, pch = 19, col = (sex %in% 'Female') + 1L,
       cex = 0.6, bty = 'l', bg.col = 'tomato',
       xlab = 'measurement 1', ylab = 'measurement 2')
legend('bottomright', pch = 19, col = 1:2, bty = 'n',
       legend = c('Male', 'Female'))
       

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