Description Usage Arguments Details Author(s) See Also Examples
Create plots with optional density histograms in the margin, colorized points by a grouping vector, contours or aggregated means of values.
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, ...)
|
x |
Vector or matrix. |
y |
Second vector to plot on y-axis. If omitted then the values in |
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 |
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 |
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 |
Either |
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 |
main |
Optional title string for the plot |
cex.lab |
Text size setting for axis labels (xlab and ylab). |
pch |
Point shape setting. If specifying |
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
|
contour.plot |
Draws a contour plot instead of a scatter plot. |
contour.kde.n |
Sets |
contour.lines |
Sets |
contour.q |
Used for setting the |
contour.lwd |
Lineweight for contour lines. |
contour.col |
Color for the contour lines. Defaults to the setting for |
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 |
aggr.err.fun |
Either |
aggr.bootstraps |
If set to a value greater than 1 then |
aggr.boot.err.mode |
See aplot.statErr |
aggr.grand.stat |
Plot grand statistic. This only comes into play if you're using |
aggr.pch |
Point shape for aggregated data points (separate from raw data points).
Note: this only works when you do NOT have |
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 |
eb.col |
Color of error bars. Defaults to value of |
eb.length |
Length of the edges of the error bar. Passed to the |
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 |
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 |
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 |
overlay.cex |
Point size for overlay points |
overlay.col |
Point color for overlay points |
highlight |
Either a logical vector the same length as |
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.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 |
mar.right |
Plot window right margin |
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.
Shawn Driscoll
plot
kde2d
contour
pointLabel
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.