## One of the examples from 'stripchart'
beeswarm(decrease ~ treatment,
data = OrchardSprays, log = TRUE,
pch = 16, col = rainbow(8))
## One of the examples from 'boxplot', with a beeswarm overlay
boxplot(len ~ dose, data = ToothGrowth,
main = "Guinea Pigs' Tooth Growth",
xlab = "Vitamin C dose mg",
ylab = "Tooth length")
beeswarm(len ~ dose, data = ToothGrowth, col = 2, add = TRUE)
## Compare the 4 methods
op <- par(mfrow = c(2,2))
for (m in c("swarm", "center", "hex", "square")) {
beeswarm(len ~ dose, data = ToothGrowth, method = m, main = m)
}
par(op)
## Demonstrate the use of 'pwcol'
data(breast)
beeswarm(time_survival ~ event_survival, data = breast,
method = 'swarm',
pch = 16, pwcol = as.numeric(ER),
xlab = '', ylab = 'Follow-up time (months)',
labels = c('Censored', 'Metastasis'))
legend('topright', legend = levels(breast$ER),
title = 'ER', pch = 16, col = 1:2)
## The list interface
distributions <- list(runif = runif(100, min = -3, max = 3),
rnorm = rnorm(100),
rlnorm = rlnorm(100, sdlog = 0.5))
beeswarm(distributions, col = 2:4)
## Demonstrate 'pwcol' with the list interface
myCol <- lapply(distributions, function(x) cut(x, breaks = quantile(x), labels = FALSE))
beeswarm(distributions, pch = 16, pwcol = myCol)
legend('bottomright', legend = 1:4, pch = 16, col = 1:4, title = 'Quartile')
Run the code above in your browser using DataLab