# jitterPoints: Jitter points for categorical variables In csoneson/iSEE: Interactive SummarizedExperiment Explorer

## Description

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.

## Usage

 ```1 2 3``` ```jitterSquarePoints(X, Y, grouping = NULL) jitterViolinPoints(X, Y, grouping = NULL, ...) ```

## Arguments

 `X` A factor corresponding to a categorical variable. `Y` A numeric vector of the same length as `X` for `jitterViolinPoints`, or a factor of the same length as `X` for `jitterSquarePoints`. `grouping` A named list of factors of the same length as `X`, specifying how elements should be grouped. `...` Further arguments to be passed to `offsetX`.

## Details

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"`.

## Value

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

## Examples

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

csoneson/iSEE documentation built on Sept. 7, 2018, 11:30 p.m.