Skip to content

Commit

Permalink
Style changes to boxplot & added aes-colour-fill-alpha.r
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeRuss committed Jun 17, 2011
2 parents af6b122 + 9fcaa52 commit 1f269f0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
53 changes: 53 additions & 0 deletions R/aes-colour-fill-alpha.r
@@ -0,0 +1,53 @@
#' aes_colour_fill_alpha
#'
#' @name aes_colour_fill_alpha
#'
#' This page demonstrates the usuage of a subgroup
#' of aesthetics; colour, fill and alpha.
#'
#' @examples
#'
#' # Bar chart example
#' c <- ggplot(mtcars, aes(factor(cyl)))
#' # Default plotting
#' c + geom_bar()
#' # To change the interior colouring use fill aesthetic
#' c + geom_bar(fill = "red")
#' # Compare with the colour aesthetic which changes just the bar outline
#' c + geom_bar(colour = "red")
#' # Combining both, you can see the changes clearer
#' c + geom_bar(fill = "white", colour = "red")
#'
#' # The aesthetic fill also takes different colouring scales
#' # setting fill equal to a factor varible uses a discrete colour scale
#' k <- ggplot(mtcars, aes(factor(cyl), fill = factor(vs)))
#' k + geom_bar()
#'
#' # Fill aesthetic can also be used with a continuous variable
#' m <- ggplot(movies, aes(x = rating))
#' m + geom_histogram()
#' m + geom_histogram(aes(fill = ..count..))
#'
#' # Some geoms don't use both aesthetics (i.e. geom_point or geom_line)
#' b <- ggplot(economics, aes(x = date, y = unemploy))
#' b + geom_line()
#' b + geom_line(colour = "green")
#' b + geom_point()
#' b + geom_point(colour = "red")
#'
#' # For large datasets with overplotting the alpha
#' # aesthetic will make the points more transparent
#' df <- data.frame(x = rnorm(5000), y = rnorm(5000))
#' h <- ggplot(df, aes(x,y))
#' h + geom_point()
#' h + geom_point(colour = alpha("black", .5))
#' h + geom_point(colour = alpha("black", 1/10))
#'
#' # Alpha can also be used to add shading
#' j <- b + geom_line()
#' j
#' yrng <- range(economics$unemploy)
#' j <- j + geom_rect(aes(NULL, NULL, xmin = start, xmax = end, fill = party),
#' ymin = yrng[1], ymax = yrng[2], data = presidential)
#' j
#' j + scale_fill_manual(values = alpha(c("blue", "red"), .3))
12 changes: 6 additions & 6 deletions R/geom-boxplot.r
Expand Up @@ -30,7 +30,7 @@
#' p + geom_boxplot(aes(fill = factor(am)))
#'
#' # Set aesthetics to fixed value
#' p + geom_boxplot(fill="grey80", colour="#3366FF")
#' p + geom_boxplot(fill = "grey80", colour = "#3366FF")
#' qplot(factor(cyl), mpg, data = mtcars, geom = "boxplot",
#' colour = I("#3366FF"))
#'
Expand All @@ -53,11 +53,11 @@
#'
#' # Using precomputed statistics
#' # generate sample data
#' abc <- adply(matrix(rnorm(100), ncol=5), 2, quantile, c(0, .25, .5, .75, 1))
#' b <- ggplot(abc, aes(x= X1, ymin=`0%`, lower=`25%`, middle=`50%`, upper=`75%`, ymax=`100%`))
#' b + geom_boxplot(stat="identity")
#' b + geom_boxplot(stat="identity") + coord_flip()
#' b + geom_boxplot(aes(fill = X1), stat="identity")
#' abc <- adply(matrix(rnorm(100), ncol = 5), 2, quantile, c(0, .25, .5, .75, 1))
#' b <- ggplot(abc, aes(x = X1, ymin = `0%`, lower = `25%`, middle = `50%`, upper = `75%`, ymax = `100%`))
#' b + geom_boxplot(stat = "identity")
#' b + geom_boxplot(stat = "identity") + coord_flip()
#' b + geom_boxplot(aes(fill = X1), stat = "identity")
GeomBoxplot <- proto(Geom, {
objname <- "boxplot"

Expand Down
12 changes: 6 additions & 6 deletions man/geom_boxplot.Rd
Expand Up @@ -34,7 +34,7 @@ p + geom_boxplot(aes(fill = factor(vs)))
p + geom_boxplot(aes(fill = factor(am)))
# Set aesthetics to fixed value
p + geom_boxplot(fill="grey80", colour="#3366FF")
p + geom_boxplot(fill = "grey80", colour = "#3366FF")
qplot(factor(cyl), mpg, data = mtcars, geom = "boxplot",
colour = I("#3366FF"))

Expand All @@ -57,8 +57,8 @@ group = round_any(year, 10, floor))

# Using precomputed statistics
# generate sample data
abc <- adply(matrix(rnorm(100), ncol=5), 2, quantile, c(0, .25, .5, .75, 1))
b <- ggplot(abc, aes(x= X1, ymin=`0\%`, lower=`25\%`, middle=`50\%`, upper=`75\%`, ymax=`100\%`))
b + geom_boxplot(stat="identity")
b + geom_boxplot(stat="identity") + coord_flip()
b + geom_boxplot(aes(fill = X1), stat="identity")}
abc <- adply(matrix(rnorm(100), ncol = 5), 2, quantile, c(0, .25, .5, .75, 1))
b <- ggplot(abc, aes(x = X1, ymin = `0\%`, lower = `25\%`, middle = `50\%`, upper = `75\%`, ymax = `100\%`))
b + geom_boxplot(stat = "identity")
b + geom_boxplot(stat = "identity") + coord_flip()
b + geom_boxplot(aes(fill = X1), stat = "identity")}

0 comments on commit 1f269f0

Please sign in to comment.