--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
I did not see any built-in functionality for this. I kind of like
simple boxplots (maybe with jittered points added), but maybe I'm old
fashioned. Anyway, it is not terribly difficult to add. An example
follows. You can see where all the options go, so if you wanted to
have different colour and style for each, just keep adding arguments
and pass them on.
Cheers,
Josh
# Data
dat <- data.frame(x = 1, y = c(1, 3, 5, 4, 5, 5, 10, 15))
# Default possibilities
ggplot(data = dat, aes(x = x, y = y)) + geom_boxplot(fill = "black",
colour = "maroon", lwd = 2)
# add another argument for the median line colour
GeomBoxplot$draw <- function(., data, ..., outlier.colour = "black",
outlier.shape = 16, outlier.size = 2, midcol = NULL) {
defaults <- with(data, data.frame(
x = x, xmin = xmin, xmax = xmax,
colour = colour, size = size,
linetype = 1, group = 1, alpha = 1,
fill = alpha(fill, alpha),
stringsAsFactors = FALSE
))
defaults2 <- defaults[c(1,1), ]
defaults3 <- defaults
if(is.null(midcol)) {midcol <- defaults[, "colour"]}
defaults3[, "colour"] <- midcol
if (!is.null(data$outliers) && length(data$outliers[[1]] >= 1)) {
outliers_grob <- with(data,
GeomPoint$draw(data.frame(
y = outliers[[1]], x = x[rep(1, length(outliers[[1]]))],
colour=I(outlier.colour), shape = outlier.shape, alpha = 1,
size = outlier.size, fill = NA), ...
)
)
} else {
outliers_grob <- NULL
}
with(data, ggname(.$my_name(), grobTree(
outliers_grob,
GeomPath$draw(data.frame(y=c(upper, ymax), defaults2), ...),
GeomPath$draw(data.frame(y=c(lower, ymin), defaults2), ...),
GeomRect$draw(data.frame(ymax = upper, ymin = lower, defaults), ...),
GeomRect$draw(data.frame(ymax = middle, ymin = middle, defaults3), ...)
)))
}
# Different colours
ggplot(data = dat, aes(x = x, y = y)) + geom_boxplot(fill = "black",
colour = "maroon", lwd = 2, midcol = "white"
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/