mplot3_x: 'mplot3': Univariate plots: index, histogram, density,...

View source: R/mplot3_x.R

mplot3_xR Documentation

mplot3: Univariate plots: index, histogram, density, QQ-line

Description

Draw plots of 1-dimensional data: index, histogram, density, and Q-Q plots.

Usage

mplot3_x(
  x,
  type = c("density", "histogram", "hd", "lhist", "index", "ts", "qqline"),
  group = NULL,
  data = NULL,
  xlab = NULL,
  ylab = NULL,
  main = NULL,
  xlim = NULL,
  ylim = NULL,
  index.ypad = 0.1,
  axes.swap = FALSE,
  axes.col = NULL,
  tick.col = NULL,
  cex = 1.2,
  col = NULL,
  alpha = 0.75,
  index.type = c("p", "l"),
  hist.breaks = "Sturges",
  hist.type = c("bars", "lines"),
  hist.probability = FALSE,
  hist.lwd = 3,
  density.line = FALSE,
  density.shade = TRUE,
  density.legend.side = 3,
  density.legend.adj = 0.98,
  density.bw = "nrd0",
  density.kernel = "gaussian",
  density.params = list(na.rm = na.rm),
  qqline.col = "#18A3AC",
  qqline.alpha = 1,
  pch = 16,
  point.col = NULL,
  point.cex = 1,
  point.bg.col = NULL,
  point.alpha = 0.66,
  hline = NULL,
  vline = NULL,
  diagonal = FALSE,
  grid = FALSE,
  grid.col = NULL,
  grid.alpha = 0.5,
  grid.lty = 3,
  grid.lwd = 1,
  annotation = NULL,
  annot.col = NULL,
  group.legend = NULL,
  group.title = "",
  group.names = NULL,
  group.side = 3,
  group.adj = 0.02,
  group.at = NA,
  text.xy = NULL,
  text.x = NULL,
  text.y = NULL,
  text.xy.cex = 1,
  text.xy.col = "white",
  line.col = "#008E00",
  x.axis.padj = -1.1,
  y.axis.padj = 0.9,
  labs.col = NULL,
  lab.adj = 0.5,
  density.avg = ifelse(type == "density", TRUE, FALSE),
  density.avg.fn = c("median", "mean"),
  density.avg.line = FALSE,
  density.avg.lwd = 1.5,
  density.avg.lty = 3,
  hline.col = "black",
  hline.lwd = 1,
  hline.lty = 1,
  vline.col = "black",
  vline.lwd = 1,
  vline.lty = 1,
  lty = 1,
  lwd = 2,
  qqline.lwd = lwd,
  density.lwd = lwd,
  theme = rtTheme,
  palette = rtPalette,
  pty = "m",
  mar = NULL,
  oma = rep(0, 4),
  xaxs = "r",
  yaxs = "r",
  autolabel = letters,
  new = FALSE,
  alpha.off = FALSE,
  na.rm = TRUE,
  par.reset = TRUE,
  filename = NULL,
  pdf.width = 6,
  pdf.height = 6,
  ...
)

Arguments

x

Numeric vector or list of vectors, one for each group. If data is provided, x is name of variable in data

type

Character: "density", "histogram", "hd" (histogram bars & density lines), "lhist" (line histogram like mhist; same as ⁠type = "hist", hist.type = "lines"⁠), "index", "ts", "qqline" Case-insensitive and supports partial matching: e.g. mplot3_x(x, "H") gives histogram

group

Vector denoting group membership. Will be converted to factor. If data is provided, group is name of variable if data

data

Optional data frame containing x data

xlab

Character: x-axis label

ylab

Character: y-axis label

main

Character: Plot title

xlim

Float vector, length 2: x-axis limits

ylim

Float vector, length 2: y-axis limits

index.ypad

Float: Expand ylim by this much for plot type "index" Default = .1 (Stops points being cut off)

index.type

Character: "p" for points (Default), "l" for lines (timeseries)

hist.breaks

See histogram("breaks")

hist.type

Character: "bars" or "lines". Default = "bars"

hist.lwd

Float: Line width for type = "histogram"; hist.type = "lines"

density.line

Logical: If TRUE, draw line for type = "density". Default = FALSE

density.shade

Logical: If TRUE, draw shaded polygon for type = "density". Default = TRUE

qqline.col

Color for Q-Q line

qqline.alpha

Float: Alpha for Q-Q line

pch

Integer: Point character.

point.cex

Float: Character expansion for points.

point.bg.col

Color: point background

hline

Vector: y-value(s) for horizontal lines.

vline

Vector: x-value(s) for vertical lines.

diagonal

Logical: If TRUE, draw diagonal line.

annotation

Character: Add annotation at the bottom right of the plot

group.legend

Logical: If TRUE, include legend with group names

group.title

Character: Title above group names

group.names

(Optional) If multiple groups are plotted, use these names if group.title = TRUE

group.side

Integer: Side to show group legend

group.adj

Float: adj for group legend. See mtext("adj")

group.at

Float: location for group legend. See mtext("at")

line.col

Color for lines

labs.col

Color for labels

lab.adj

Adjust the axes labels. 0 = left adjust; 1 = right adjust; .5 = center (Default)

density.avg

Logical: If TRUE, print mean of x along plot. Default = TRUE, for type = "density"

density.avg.fn

Character: "median" or "mean". Function to use if density.avg = TRUE. Default = "median"

density.avg.line

Logical: If TRUE, draw vertical lines at the density average x-value

density.avg.lwd

Float: Line width for density.avg.line. Default = 1.5

density.avg.lty

Integer: Line type for density.avg.line. Default = 3

hline.col

Color for horizontal line(s)

hline.lwd

Float: Width for horizontal line(s)

hline.lty

Integer: Line type for horizontal line(s)

vline.col

Color for vertical lines

vline.lwd

Float: Width for vertical lines

vline.lty

Integer: Line type for vertical lines

lty

Integer: Line type. See par("lty")

lwd

Integer: Line width. Used for ⁠type = "ts" or "density"⁠

theme

Character: Run themes() for available themes

palette

Vector of colors, or Character defining a builtin palette - get options with rtpalette()

pty

Character: "s" gives a square plot; "m" gives a plot that fills graphics device size. Default = "m" (See par("pty"))

mar

Float, vector, length 4: Margins; see par("mar")

oma

Float, vector, length 4: Outer margins; see par("oma")

xaxs

Character: "r": Extend plot x-axis limits by 4% on either end; "i": Use exact x-axis limits.

yaxs

Character: as xaxs for the y-axis.

autolabel

Character vector to be used to generate autolabels when using rtlayout with autolabel = TRUE.

new

Logical: If TRUE, add plot to existing plot. See par("new")

na.rm

Logical: Will be passed to all functions that support it. If set to FALSE, input containing NA values will result in error, depending on the type

par.reset

Logical: If TRUE, reset par setting before exiting.

filename

Path to file: If supplied, plot will be printed to file

pdf.width

Float: Width in inches for pdf output (if filename is set).

pdf.height

Float: Height in inches for pdf output.

...

Additional arguments to be passed to theme function

Details

You can group data either by supplying x as a list where each element contains one vector per group, or as a data frame where each column represents group, or by providing a group variable, which will be converted to factor. For bivariate plots, see mplot3_xy and mplot3_xym. For heatmaps, see mplot3_heatmap To plot histograms of multiple groups, it's best to use hist.type = "lines", which will use mhist and space apart the breaks for each group

Value

Invisibly returns the output of density, hist, qqnorm, or NULL

Author(s)

E.D. Gennatas

See Also

mplot3_xy, mplot3_xym, mplot3_heatmap

Examples

## Not run: 
mplot3_x(iris)
mplot3_x(split(iris$Sepal.Length, iris$Species), xlab = "Sepal Length")

## End(Not run)


egenn/rtemis documentation built on Dec. 17, 2024, 6:16 p.m.