dodge2 | R Documentation |
Dodge and center overlapping points by group. Spreads scattered points
similar to jitter
but symmetrically. Although the default method
can be used, it is recommended to use the formula method for ease of use
and to set useful defaults for jit
and dist
.
dodge2(x, ...)
## Default S3 method:
dodge2(x, y, jit = NULL, dist = NULL, ...)
## S3 method for class 'formula'
dodge2(formula, data = NULL, ...)
x |
grouping variables or, equivalently, positions along x-axis |
... |
additional arguments passed to or from other methods |
y |
a numeric vector of data, y-values |
jit , dist |
jittering parameters; |
formula |
a |
data |
optional matrix or data frame containing the variables in
|
jitter
; tplot
; dodge
;
beeswarm::beeswarm
## these are equivalent ways to call dodge2:
dodge2(mpg ~ gear + vs, mtcars)
with(mtcars, dodge2(list(gear, vs), mpg))
dodge2(mtcars[, c('gear', 'vs')], mtcars$mpg)
## compare to overlapping points and jittering
sp <- split(mtcars$mpg, do.call(interaction, mtcars[, c('gear','vs')]))
plot.new()
op <- par(cex = 2)
plot.window(c(0.5, 6.5), c(10, 35))
for (ii in seq_along(sp))
points(rep(ii, length(sp[[ii]])), sp[[ii]])
for (ii in seq_along(sp))
points(jitter(rep(ii, length(sp[[ii]]))), sp[[ii]], col = 4, pch = 1)
points(dodge2(mpg ~ gear + vs, mtcars), col = 2, pch = 4)
legend('topleft', pch = c(1, 1, 4), col = c(1, 4, 2), cex = 0.8,
legend = c('overlapping', 'random jitter', 'dodging'))
par(op)
## practical use
boxplot(disp ~ vs + gear, data = mtcars)
points(dodge2(disp ~ vs + gear, data = mtcars))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.