Description Usage Arguments Details Value Author(s) Examples
Add quasi-random jitter on the x-axis for violin plots when the x-axis variable is categorical. Add random jitter within a rectangular area for square plots when both x- and y-axis variables are categorical.
1 2 3 | jitterSquarePoints(X, Y, grouping = NULL)
jitterViolinPoints(X, Y, grouping = NULL, ...)
|
X |
A factor corresponding to a categorical variable. |
Y |
A numeric vector of the same length as |
grouping |
A named list of factors of the same length as |
... |
Further arguments to be passed to |
The jitterViolinPoints
function calls offsetX
to obtain quasi-random jittered x-axis values.
This reflects the area occupied by a violin plot, though some tuning of arguments in ...
may be required to get an exact match.
The jitterSquarePoints
function will uniformly jitter points on both the x- and y-axes.
The jitter area is a square with area proportional to the frequency of the paired levels in X
and Y
.
If either factor only has one level, the jitter area becomes a rectangle that can be interpreted as a bar plot.
If grouping
is specified, the values corresponding to each point defines a single combination of levels.
Both functions will then perform jittering separately within each unique combination of levels.
This is useful for obtaining appropriate jittering when points are split by group, e.g., during faceting.
If grouping!=NULL
for jitterSquarePoints
the statistics in the returned summary
data.frame will be stratified by unique combinations of levels.
To avoid clashes with existing fields, the names in grouping
should not be "X"
, "Y"
, "Freq"
, "XWidth"
or "YWidth"
.
For jitterViolinPoints
, a numeric vector is returned containing the jittered x-axis coordinates for all points.
For jitterSquarePoints
, a list is returned with numeric vectors X
and Y
, containing jittered coordinates on the x- and y-axes respectively for all points;
and summary
, a data.frame of frequencies and side lengths for each unique pairing of X/Y levels.
Aaron Lun
1 2 3 4 5 6 7 8 9 10 | X <- factor(sample(LETTERS[1:4], 100, replace=TRUE))
Y <- rnorm(100)
(out1 <- jitterViolinPoints(X=X, Y=Y))
Y2 <- factor(sample(letters[1:3], 100, replace=TRUE))
(out2 <- jitterSquarePoints(X=X, Y=Y2))
grouped <- sample(5, 100, replace=TRUE)
(out3 <- jitterViolinPoints(X=X, Y=Y, grouping=list(FacetRow=grouped)))
(out4 <- jitterSquarePoints(X=X, Y=Y2, grouping=list(FacetRow=grouped)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.