mplot3_xy: 'mplot3': XY Scatter and line plots

View source: R/mplot3_xy.R

mplot3_xyR Documentation

mplot3: XY Scatter and line plots

Description

Plot points and lines with optional fits and standard error bands

Usage

mplot3_xy(
  x,
  y = NULL,
  fit = NULL,
  formula = NULL,
  se.fit = FALSE,
  fit.params = NULL,
  error.x = NULL,
  error.y = NULL,
  cluster = NULL,
  cluster.params = list(),
  data = NULL,
  type = "p",
  group = NULL,
  xlab = NULL,
  ylab = NULL,
  main = NULL,
  xlim = NULL,
  ylim = NULL,
  xpd = TRUE,
  xaxs = "r",
  yaxs = "r",
  log = "",
  rsq = NULL,
  rsq.pval = FALSE,
  rsq.side = 1,
  rsq.adj = 0.98,
  rsq.col = NULL,
  rsq.line = NULL,
  fit.error = FALSE,
  fit.error.side = 1,
  fit.error.padj = NA,
  xaxp = NULL,
  yaxp = NULL,
  scatter = TRUE,
  axes.equal = FALSE,
  pty = "m",
  annotation = NULL,
  annotation.col = NULL,
  x.axis.at = NULL,
  x.axis.labs = TRUE,
  y.axis.at = NULL,
  y.axis.labs = TRUE,
  xlab.adj = 0.5,
  ylab.adj = 0.5,
  mar = NULL,
  oma = rep(0, 4),
  point.cex = 1,
  point.bg.col = NULL,
  pch = ifelse(is.null(point.bg.col), 16, 21),
  line.col = NULL,
  line.alpha = 0.66,
  lwd = 1,
  lty = 1,
  marker.col = NULL,
  marker.alpha = NULL,
  error.x.col = NULL,
  error.y.col = NULL,
  error.x.lty = 1,
  error.y.lty = 1,
  error.x.lwd = 1,
  error.y.lwd = 1,
  error.arrow.code = 3,
  fit.col = NULL,
  fit.lwd = 2.5,
  fit.alpha = 1,
  fit.legend = ifelse(is.null(fit), FALSE, TRUE),
  se.lty = "poly",
  se.lwd = 1,
  se.col = NULL,
  se.alpha = 0.5,
  se.times = 1.96,
  se.border = FALSE,
  se.density = NULL,
  hline = NULL,
  hline.col = NULL,
  hline.lwd = 1.5,
  hline.lty = 3,
  vline = NULL,
  vline.lwd = 1.5,
  vline.col = "blue",
  vline.lty = 3,
  diagonal = FALSE,
  diagonal.inv = FALSE,
  diagonal.lwd = 1.5,
  diagonal.lty = 1,
  diagonal.col = "gray50",
  diagonal.alpha = 1,
  group.legend = NULL,
  group.title = NULL,
  group.names = NULL,
  group.side = 3,
  group.adj = 0.02,
  group.padj = 2,
  group.at = NA,
  fit.legend.col = NULL,
  fit.legend.side = 3,
  fit.legend.adj = 0.02,
  fit.legend.padj = 2,
  fit.legend.at = NA,
  rm.na = TRUE,
  theme = rtTheme,
  palette = rtPalette,
  order.on.x = NULL,
  autolabel = letters,
  new = FALSE,
  par.reset = TRUE,
  return.lims = FALSE,
  pdf.width = 6,
  pdf.height = 6,
  trace = 0,
  filename = NULL,
  ...
)

Arguments

x

Numeric vector or list of vectors for x-axis. If data is provided, name of variable, unquoted.

y

Numeric vector of list of vectors for y-axis If data is provided, name of variable, unquoted.

fit

Character: rtemis model to calculate y ~ x fit. Options: see select_learn() Can also be Logical, which will give a GAM fit if TRUE. If you specify "NLA", the activation function should be passed as a string.

formula

Formula: Provide a formula to be solved using s_NLS. If provided, fit is forced to 'nls'. e.g. y ~ b * m ^ x for a power curve. Note: nls is powerful but is prone to errors and warnings. Use single letters for parameter names, no numbers.

se.fit

Logical: If TRUE, draw the standard error of the fit

fit.params

List: Arguments for learner defined by fit. Default = NULL, i.e. use default learner parameters

error.x

Vector, float: Error in x (e.g. standard deviation) will be plotted as bars around point

error.y

Vector, float: Error in y (e.g. standard deviation) will be plotted as bars around point

cluster

Character: Clusterer name. Will cluster data.frame(x, y) and pass result to group. Run select_clust for options

cluster.params

List: Names list of parameters to pass to the cluster function

data

(Optional) data frame, where x and y are defined

type

Character: "p" for points, "l" for lines, "s" for steps. Default = "p". If x and/or y contains multiple vectors, type can be a vector, e.g. c("p", "l", "l") will give a set of points and two sets of lines. Otherwise, type is recycled to length of x

group

Vector: will be converted to factor. If data is provided, name of variable, unquoted.

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

xpd

Logical or NA: FALSE: plotting clipped to plot region; TRUE: plotting clipped to figure region; NA: plotting clipped to device region.

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.

log

Character: "x", "y", or "xy", defines if either or both axes should be log-transformed.

rsq

Logical: If TRUE, add legend with R-squared (if fit is not NULL)

rsq.pval

Logical: If TRUE, add legend with R-squared and its p-value, if fit is not NULL

rsq.side

Integer: [1:4] Where to place the rsq annotation. Default = 1 (i.e. bottom)

rsq.adj

Float: Adjust rsq annotation. See ⁠mtext "adj"⁠

rsq.col

Color: Color for rsq annotation. Default = NULL, which results in fit.col

rsq.line

Numeric: Passed to ⁠mtext "line"⁠ to place R-squared annotation.

fit.error

Logical: If TRUE: draw fit error annotation. Default = NULL, which results in TRUE, if fit is set

fit.error.side

Integer [1:4]: Which side to draw fit.error on.

fit.error.padj

Float: See mtext:padg Default = NA

xaxp

See par("xaxp")

yaxp

See par("yaxp")

scatter

Logical: If TRUE, plot (x, y) scatter points.

axes.equal

Logical: Should axes be equal? Defaults to FALSE

pty

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

annotation

Character: Add annotation at the bottom right of the plot

annotation.col

Color for annotation

x.axis.at

Float, vector: x coordinates to place tick marks. Default = NULL, determined by graphics::axis aautomatically

x.axis.labs

See axis("labels")

y.axis.at

As x.axis.at for y-axis

y.axis.labs

See axis("labels")

xlab.adj

Float: adj for xlab (See par("adj"))

ylab.adj

Float: adj for ylab (See par("adj"))

mar

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

oma

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

point.cex

Float: Character expansion for points.

point.bg.col

Color: point background

pch

Integer: Point character.

line.col

Color for lines

line.alpha

Float [0, 1]: Transparency for lines

lwd

Float: Line width

lty

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

marker.col

Color for marker

marker.alpha

Float [0, 1]: Transparency for markers

error.x.col

Color for x-axis error bars

error.y.col

Color for y-axis error bars

error.x.lty

Integer: line type for x-axis error bars

error.y.lty

Integer: line type for y-axis error bars

error.x.lwd

Float: Line width for x-axis error bars

error.y.lwd

Float: Line width for y-axis error bars

error.arrow.code

Integer: Type of arrow to draw for error bars. See arrows("code")

fit.col

Color: Color of the fit line.

fit.lwd

Float: Fit line width

fit.alpha

Float [0, 1]: Transparency for fit line

fit.legend

Logical: If TRUE, show fit legend

se.lty

How to draw the se.fit "poly" draws a polygon around the fit line, otherwise an integer defines the lty (line type) for lines to be drawn

se.lwd

Float: Line width for standard error bounds

se.col

Color for se.fit

se.alpha

Alpha for se.fit

se.times

Draw polygon or lines at +/- se.times * standard error of fit. Defaults to 1.96, which corresponds to 95 percent confidence interval

se.border

Define border of polygon for se.fit. See border in graphics::polygon

se.density

Density of shading line of polygon for se.fit. See density in graphics::polygon

hline

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

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

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

vline.lwd

Float: Width for vertical lines

vline.col

Color for vertical lines

vline.lty

Integer: Line type for vertical lines

diagonal

Logical: If TRUE, draw diagonal line.

diagonal.inv

Logical: If TRUE, draw inverse diagonal line. Will use diagonal.lwd, diagonal.lty, diagonal.col, diagonal.alpha (Note: it only makes sense to use only one of diagonal or diagonal.inv)

diagonal.lwd

Float: Line width for diagonal.

diagonal.lty

Integer: Line type for diagonal.

diagonal.col

Color: Color for diagonal.

diagonal.alpha

Float: Alpha for diagonal

group.legend

Logical: If TRUE, place group.names in a legend

group.title

Character: Group title, shown above group names. e.g. if group names are c("San Francisco", "Philadelphia"), group.title can be "City"

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.padj

Float: padj for group legend See mtext("padj")

group.at

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

fit.legend.col

Color for fit legend

fit.legend.side

Integer: Side for fit legend

fit.legend.adj

Float: adj for fit legend

fit.legend.padj

Float: padj for fit legend

fit.legend.at

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

rm.na

Logical: If TRUE, remove all NA values pairwise between x and y. Set to FALSE if you know your data has no missing values.

theme

Character: Run themes() for available themes

palette

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

order.on.x

Logical: If TRUE, order (x, y) by increasing x. Default = NULL: will be set to TRUE if fit is set, otherwise FALSE

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")

par.reset

Logical: If TRUE, reset par setting before exiting.

return.lims

Logical: If TRUE, return xlim and ylim.

pdf.width

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

pdf.height

Float: Height in inches for pdf output.

trace

Integer: If > 0, pass verbose = TRUE to the cluster and fit functions, if used.

filename

Character: Path to file to save plot. Default = NULL

...

Additional arguments to be passed to theme function

Author(s)

E.D. Gennatas

Examples

## Not run: 
set.seed(1999)
x <- rnorm(500)
ycu <- x^3 + 12 + rnorm(500)
mplot3_xy(x, ycu)
mplot3_xy(x, ycu, fit = "gam")
ysq <- x^2 + 3 + rnorm(500)
mplot3_xy(x, list(squared = ysq, cubed = ycu), fit = "gam")

## End(Not run)

egenn/rtemis documentation built on April 24, 2024, 6:58 p.m.