aplot: Mega plotting function.

Description Usage Arguments Details Author(s) See Also Examples

Description

Create plots with optional density histograms in the margin, colorized points by a grouping vector, contours or aggregated means of values.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
aplot(x, y = NULL, grid = TRUE, col = "#660000", cex = 1, add = FALSE,
  groups = NULL, groups2 = NULL, xlab = "x", ylab = "y",
  col.grid = "grey", lty.grid = "dashed", bg.col = "white",
  theme = c("none", "gg"), cex.axis = 0.7, xlim = NULL, ylim = NULL,
  xpad = 0, ypad = xpad, main = NULL, cex.lab = 1, pch = 20,
  symm.axis = FALSE, show.density = FALSE, density.mar = 0.2,
  scale.density = FALSE, contour.plot = FALSE, contour.kde.n = 512,
  contour.lines = 10, contour.q = c(0, 1), contour.lwd = 1,
  contour.col = col, contour.with.points = FALSE, aggr.plot = FALSE,
  aggr.fun = c("mean", "median"), aggr.err.fun = c("sd", "sem", "var",
  "ci"), aggr.bootstraps = 1, aggr.boot.err.mode = 1,
  aggr.grand.stat = FALSE, aggr.pch = 19, aggr.cex = 1,
  aggr.with.points = FALSE, eb = NULL, eb.col = "#00000044",
  eb.length = 0.05, eb.code = 3, eb.angle = 90, eb.lwd = 1,
  show.legend = TRUE, legend.cols = 1, legend.pos = "topleft",
  legend.cex = 0.8, legend.horiz = FALSE, identify = FALSE,
  cex.labels = 0.7, col.labels = "black", labels = NULL, vline = NULL,
  vline.col = "black", vline.lty = "solid", vline.lwd = 1, hline = NULL,
  hline.col = vline.col, hline.lty = vline.lty, hline.lwd = vline.lwd,
  overlay.pch = 1, overlay = FALSE, overlay.cex = 1,
  overlay.col = "black", highlight = NULL, highlight.cex = cex,
  highlight.col = "dodgerblue", highlight.pch = pch,
  highlight.labels = NULL, highlight.label.cex = cex.labels,
  highlight.label.col = highlight.col, mar.bottom = 3.1, mar.left = 3.1,
  mar.top = 0.8, mar.right = 0.8, ...)

Arguments

x

Vector or matrix.

y

Second vector to plot on y-axis. If omitted then the values in x are plotted on the y-axis with x-axis values 1:length(x).

grid

Whether or not to draw a grid in the plot

col

Color for plotted objects. This field can be a little flexible for instance if you want to provide specific colors for each point or if you are specifying groups and you want to assign colors per group. If you want to assign colors by group then the length of this vector of colors should match the number of levels in the grouping vector.

cex

See plot. Size setting for points in point-plots.

add

Indicates that the call should add to the current plot instead of replace it.

groups

Grouping vector for plotted objects. Each group will be plotted with a separate color.

groups2

Second grouping for grouping the groups specified in groups. Sometimes the average of the averaged values is more appropriate than the overall average.

xlab

String label for x-axis. Default: "x"

ylab

String label for y-axis. Default: "y"

col.grid

Color for grid lines. Default: grey

lty.grid

Linetype for grid lines. Default: dashed

bg.col

Background color for the plot area. This is also controlled with the theme setting. Default: white.

theme

Either none or gg. gg mimics the default plot style of ggplot2.

cex.axis

Size setting for axis text.

xlim

Limits for x-axis

ylim

Limits for y-axis

xpad

Padding for x-axis. This is calculated as a ratio of the range of values on the x-axis. Useful for making it so the edges of the plot are further from the data when you're adding labels to points or trying to fit a legend in the plot area.

ypad

See xpad. By default ypad is set to the same value as xpad

main

Optional title string for the plot

cex.lab

Text size setting for axis labels (xlab and ylab).

pch

Point shape setting. If specifying groups this value can be set to a vector specifying a specific shape per group.

symm.axis

Forces the x and y-axis ranges to be identical.

show.density

Draws density histogram, using density in the margin of the plot

density.mar

Margin setting for density.

scale.density

Scales the density's y-axis by the number of input values to the density function call. Sometimes useful when you want the size of a group to by represented in the height of the density plot when using groups

contour.plot

Draws a contour plot instead of a scatter plot.

contour.kde.n

Sets n in kde2d function call. Default: 512

contour.lines

Sets nlevels in contour function call. Default: 10

contour.q

Used for setting the zlim setting in contour. This setting controls how you might want to clip the full z-range of the density calculated. Default is to display the full range.

contour.lwd

Lineweight for contour lines.

contour.col

Color for the contour lines. Defaults to the setting for col

contour.with.points

Set to TRUE to overaly a scatter plot of the x/y data points on top of the contour plot

aggr.plot

Aggregates data by mean or median and plots the result. See details.

aggr.fun

Either mean or median. See aplot.statErr

aggr.err.fun

Either sd, sem, var, or ci. See aplot.statErr

aggr.bootstraps

If set to a value greater than 1 then aggr.fun is bootstrapped. See aplot.statErr

aggr.boot.err.mode

See aplot.statErr

aggr.grand.stat

Plot grand statistic. This only comes into play if you're using groups

aggr.pch

Point shape for aggregated data points (separate from raw data points). Note: this only works when you do NOT have groups specified. Otherwise the point style is set to match the group's point style.

aggr.cex

Point size for aggregated data points.

aggr.with.points

Plot input data points as well as the aggregated points.

eb

List with error bar high/low values for plot data. List members should be named x and/or y and each one should be a two-column matrix specifying the error bar boundaries. 'low' is first column and 'high' is second column.

eb.col

Color of error bars. Defaults to value of col

eb.length

Length of the edges of the error bar. Passed to the length setting of the arrows function.

eb.code

Sets the kind of arrowhead. Default is 3 which draws a typical error bar.

eb.angle

Sets angle from the shaft of the error bar to the edge of the head.

eb.lwd

Line weight of the error bars.

show.legend

Adds a legend into the plot area when groups is set

legend.cols

Number of columns in the legend

legend.pos

Position of the legend. See legend for available options.

legend.cex

Size setting for the legend. Controls both point and font sizes.

legend.horiz

Draws the legend horizontally. See legend for details

identify

Allows you to pick points on an existing plot. When finished picking points then point indices or labels are drawn in the plot area. Labels can be set with labels

cex.labels

Size setting for point labels

col.labels

Color for point labels

labels

Vector of labels for points. Should be equal in length to the number of plotted points.

vline

Vector of values specifying x-positions for vertical lines to be drawn.

vline.col

Color for vertical lines.

vline.lty

Linetype for vertical lines.

vline.lwd

Line thickness for vertical lines.

hline

Vector of values specifying y-positions for horizontal lines to be drawn.

hline.col

Color for horizontal lines

hline.lty

Linetype for horizontal lines

hline.lwd

Line thickness for horizontal lines

overlay.pch

Point shape for overlay points

overlay

If set to TRUE then instead of making a new plot the plot data is passed to points and plotted on top of the current plot. Useful for highlighting a subset of your data in a different color. Note that you could also accomplish that using a groups vector.

overlay.cex

Point size for overlay points

overlay.col

Point color for overlay points

highlight

Either a logical vector the same length as x or a vector of indices to x. Points specified in this way are added like an overlay to the main plot data with separate settings for point size, color, and shape. You may also include separate highlight labels and control their size and color.

highlight.cex

Point size for highlighted points.

highlight.col

Point color for highlighted points.

highlight.pch

Point shape for highlighted points.

highlight.labels

Labels for highlighted points. Should be the same length vector as highlight

highlight.label.cex

Font size for highlight labels

highlight.label.col

Font color for highlight labels

mar.bottom

Plot window bottom margin

mar.left

Plot window left margin

mar.top

Plot window top margin. This is adjusted automatically when you add a title with main

mar.right

Plot window right margin

Details

This plotting function provides a lot of options. You can provide values to plot and a grouping vector with groups to colorize points by group. If you'd like to plot the group means with error bars specify aggr.plot=TRUE and then choose your preferred setting for error bars by setting aggr.err.fun.

When creating contour plots it is recommended to set xpad to avoid contour lines being clipped at the edges of the plot.

To label some points on the plot and not others you can create a single label vector and set values to NA for those that you do not want called out.

Author(s)

Shawn Driscoll

See Also

plot

kde2d

contour

pointLabel

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# create some data for plotting
x <- c(rnorm(30, -2, 1), rnorm(30, 2, 1))
y <- x * rnorm(60, 0, 0.5)
groups <- rep(c("A", "B"), each=30)

# Create scatter plot of points
aplot(x, y)

# Plot again showing groups with colors
aplot(x, y, groups=groups)

# Plot group means with error bars
aplot(x, y, groups=groups, aggr.plot=TRUE)

# Plot bootstrapped group means with 95% confidence interval of the means
aplot(x, y, groups=groups, aggr.plot=TRUE, aggr.bootstraps=1e3, 
  aggr.err.fun="ci")

# Add the raw data points, increase the point size for the means and 
# set group specific point shapes
aplot(x, y, groups=groups, aggr.plot=TRUE, aggr.bootstraps=1e3, 
  aggr.err.fun="ci", aggr.with.points=TRUE, aggr.cex=2, pch=c(17, 15))

# Add density histograms in the margins
aplot(x, y, groups=groups, aggr.plot=TRUE, aggr.bootstraps=1e3, 
  aggr.err.fun="ci", aggr.with.points=TRUE, aggr.cex=2, pch=c(17, 15), 
  show.density=TRUE)

# Make a contour plot of the raw data. Add some padding so that the
# contours do not get clipped at the ends of the plot.
aplot(x, y, contour.plot=TRUE, xpad=0.5)

# Split data by groups, add in the raw data points.
aplot(x, y, contour.plot=TRUE, xpad=0.5, groups=groups, 
  contour.with.points=TRUE)

# Put everything in the plot.
aplot(x, y, contour.plot=TRUE, xpad=0.5, groups=groups, 
  contour.with.points=TRUE, aggr.plot=TRUE, aggr.cex=2, eb.lwd=2, 
  pch=c(17, 15), show.density=TRUE)

PfaffLab/aplot documentation built on May 31, 2019, 10:45 p.m.