Learn R Programming

oaPlots (version 0.0.25)

pointsOnBoxplot.default: Draw Points on Top of a Boxplot using Appropriate Shifting

Description

Draw Points on Top of a Boxplot using Appropriate Shifting

Usage

"pointsOnBoxplot"(x = NULL, y = NULL, totalSpread = 0.3, roundTo = NULL, horizontal = FALSE, ...)

Arguments

x
vector of numeric values that were used to create boxplots
y
vector of values representing a categorical variable
totalSpread
total spread of point plotting range within a boxplot. Defaults to 0.3 so that points plot between 0.85 and 1.15
roundTo
optional rounding interval. For example, if given roundTo = 0.25, all numeric x values will be rounded to the nearest quarter
horizontal
logical indicating if the boxplots should be horizontal; default FALSE means vertical boxes.
...
further parameters to be passed to the points function

Value

points are drawn to the current device

Examples

Run this code
# Examples run in the formula and default methods
x2 <- runif(50, 0, 10);
table(customRound(x2, roundTo = 0.5))
boxplot(x2)
pointsOnBoxplot(x2, pch = 19, roundTo = 0.5)

# Set up input data
x <- c(sample(1:5, size = 25, replace = TRUE), rpois(25, lambda = 4))
colVec <- c(rep("olivedrab", 10), rep("red", 5), rep("goldenrod", 15),
    rep("red", 15), rep("olivedrab", 5))
y <- rep(c("Awesome Rats", "Stupid Rats"), each = 25)
y2 <- rep(c("Open", "Analytics"), 25)

x2 <- c(1, 2, 2, 3, 3, 1, 1, 1, 4, 5)
y3 <- c(rep("A", 5), rep("B", 5))
levels(y3) <- c("A", "B", "C")

boxplot(x ~ y, horizontal = TRUE)
pointsOnBoxplot(x ~ y, horizontal = TRUE)

boxplot(x ~ y)
pointsOnBoxplot(x = x, y = y, col = colVec, pch = 19, cex = 2)

boxplot(x ~ y + y2)
pointsOnBoxplot(x ~ y + y2, col = colVec, pch = 19, cex = 2)

Run the code above in your browser using DataLab