Skip to content

Commit

Permalink
Nice legend for boxplots. Tweak default size scale
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Feb 27, 2008
1 parent 72ff2c2 commit abbc246
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Improved documentation
* functions are silently dropped (e.g. aes(colour=col))
* scales do not try and map variables than don't exist (fixes some rather obscure bugs)

* geom_boxplot: now has it's own legend which actually looks like a boxplot
* scale_size: changed default range to [0.5, 3] to better reflect new sizing decisions
* geom_boxplot: reports if missing values removed
* geom_boxplot: deals with continuous x-axis and grouping much better
* coord_polar: add start and direction parameters, giving more control over the layout of the polar coords
Expand Down
17 changes: 14 additions & 3 deletions R/geom-interval-boxplot.r
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@ GeomBoxplot <- proto(GeomInterval, {

objname <- "boxplot"
desc <- "Box and whiskers plot"
guide_geom <- function(.) "tile"
guide_geom <- function(.) "boxplot"

draw_legend <- function(., data, ...) {
data <- aesdefaults(data, .$default_aes(), list(...))
gp <- with(data, gpar(col=colour, fill=fill, lwd=size * .pt))

gTree(children = gList(
linesGrob(0.5, c(0.1, 0.9)),
rectGrob(height=0.5, width=0.75),
linesGrob(c(0.125, 0.875), 0.5)
), gp = gp)
}
icon <- function(.) {
gTree(children=gList(
segmentsGrob(c(0.3, 0.7), c(0.1, 0.2), c(0.3, 0.7), c(0.7, 0.95)),
Expand Down Expand Up @@ -50,13 +61,13 @@ GeomBoxplot <- proto(GeomInterval, {
# Add aesthetic mappings
p + geom_boxplot(aes(fill=cyl))
p + geom_boxplot(aes(fill=factor(cyl)))
p + geom_boxplot(aes(colour=cyl), size=2)
p + geom_boxplot(aes(colour=cyl), size=1)

# Dodged boxplots
# - automatically split when an aesthetic variable is a factor
p + geom_boxplot(aes(colour=factor(am)))
p + geom_boxplot(aes(fill=factor(vs)), colour="black")
p + geom_boxplot(aes(size=factor(gear))) + scale_size(to=c(0.5, 2))
p + geom_boxplot(aes(size=factor(gear)))

# Set aesthetics to fixed value
p + geom_boxplot(fill="black", colour="white", size=1)
Expand Down
2 changes: 1 addition & 1 deletion R/scale-size.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ScaleSize <- proto(ScaleContinuous, expr={
common <- NULL
.input <- .output <- "size"

new <- function(., name=NULL, to=c(1, 5)) {
new <- function(., name=NULL, to=c(0.2, 3)) {
.$proto(name=name, .range=to)
}

Expand Down

0 comments on commit abbc246

Please sign in to comment.