Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Doc tweaks

  • Loading branch information...
commit e0dd289a954a87eb4272fd402e32412d64c31b3b 1 parent 4e1a2b8
@hadley authored
View
2  DESCRIPTION
@@ -39,6 +39,8 @@ Collate:
'aaa-.r'
'aaa-constants.r'
'aaa-html.r'
+ 'aes-colour-fill-alpha.r'
+ 'aes-linetype-size-shape.r'
'aes.r'
'annotation.r'
'bench.r'
View
3  R/aes-colour-fill-alpha.r
@@ -1,7 +1,7 @@
#' Colour related aesthetics: colour, fill and alpha
#'
#' @name aes_colour_fill_alpha
-#' @alias colour color fill alpha
+#' @aliases colour color fill alpha
#'
#' This page demonstrates the usage of a sub-group
#' of aesthetics; colour, fill and alpha.
@@ -56,3 +56,4 @@
#' ymin = yrng[1], ymax = yrng[2], data = presidential)
#' j
#' j + scale_fill_manual(values = alpha(c("blue", "red"), .3))
+NULL
View
3  R/aes-linetype-size-shape.r
@@ -1,7 +1,7 @@
#' Differentiation related aesthetics: linetype, size, shape
#'
#' @name aes_linetype_size_shape
-#' @alias linetype size shape
+#' @aliases linetype size shape
#'
#' This page demonstrates the usage of a sub-group
#' of aesthetics; linetype, size and shape.
@@ -61,3 +61,4 @@
#' # background colour (fill)
#' s + geom_point(aes(shape = z), size = 4, colour = "Red")
#' s + geom_point(aes(shape = z), size = 4, colour = "Red", fill = "Black")
+NULL
View
72 man/aes_colour_fill_alpha.Rd
@@ -0,0 +1,72 @@
+\name{aes_colour_fill_alpha}
+\title{Colour related aesthetics: colour, fill and alpha...}
+
+\description{
+ Colour related aesthetics: colour, fill and alpha
+}
+\alias{colour}
+\alias{color}
+\alias{fill}
+\alias{alpha}
+\alias{This}
+\alias{page}
+\alias{demonstrates}
+\alias{the}
+\alias{usage}
+\alias{of}
+\alias{a}
+\alias{sub-group}
+\alias{of}
+\alias{aesthetics;}
+\alias{colour,}
+\alias{fill}
+\alias{and}
+\alias{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 more clearly
+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))
+
+#If a geom uses both fill and colour, alpha will only modify the fill colour
+c + geom_bar(fill = "dark grey", colour = "black")
+c + geom_bar(fill = "dark grey", colour = "black", alpha = 1/3)
+
+# 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))}
View
75 man/aes_linetype_size_shape.Rd
@@ -0,0 +1,75 @@
+\name{aes_linetype_size_shape}
+\title{Differentiation related aesthetics: linetype, size, shape...}
+
+\description{
+ Differentiation related aesthetics: linetype, size, shape
+}
+\alias{linetype}
+\alias{size}
+\alias{shape}
+\alias{This}
+\alias{page}
+\alias{demonstrates}
+\alias{the}
+\alias{usage}
+\alias{of}
+\alias{a}
+\alias{sub-group}
+\alias{of}
+\alias{aesthetics;}
+\alias{linetype,}
+\alias{size}
+\alias{and}
+\alias{shape.}
+\examples{# Line types should be specified with either an integer, a name, or with a string of
+# an even number (up to eight) of hexidecimal digits which give the lengths in
+# consecutive positions in the string.
+# 0 = blank, 1 = solid, 2 = dashed, 3 = dotted, 4 = dotdash, 5 = longdash, 6 = twodash
+
+# Data
+df <- data.frame(x = 1:10 , y = 1:10)
+f <- ggplot(df, aes(x = x, y = y))
+f + geom_line(linetype = 2)
+f + geom_line(linetype = "dotdash")
+# An example with hex strings, the string "33" specifies three units on followed
+# by three off and "3313" specifies three units on followed by three off followed
+# by one on and finally three off.
+f + geom_line(linetype = "3313")
+
+# Mapping line type from a variable
+ec_scaled <- data.frame(date = economics$date, rescaler(economics[, -(1:2)], "range"))
+ecm <- melt(ec_scaled, id = "date")
+qplot(date, value, data = ecm, geom = "line", linetype = variable)
+
+# Size examples
+# Should be specified with a numerical value (in millimetres),
+# or from a variable source
+p <- ggplot(mtcars, aes(wt, mpg))
+p + geom_point(size = 4)
+p + geom_point(aes(size = qsec))
+p + geom_point(size = 2.5) + geom_hline(yintercept = 25, size = 3.5)
+
+# Shape examples
+# Shape takes four types of values: an integer in [0, 25],
+# a single character-- which uses that character as the plotting symbol,
+# a . to draw the smallest rectangle that is visible (i.e., about one pixel)
+# an NA to draw nothing
+p + geom_point()
+p + geom_point(shape = 5)
+p + geom_point(shape = "k", size = 3)
+p + geom_point(shape = ".")
+p + geom_point(shape = NA)
+
+# Shape can also be mapped from a variable
+p + geom_point(aes(shape = factor(cyl)))
+# Compare to this plot which uses the values of cyl
+p + geom_point(aes(shape = cyl))
+
+# A look at all 25 symbols
+df2 <- data.frame(x = 1:5 , y = 1:25, z = 1:25)
+s <- ggplot(df2, aes(x = x, y = y))
+s + geom_point(aes(shape = z), size = 4)
+# While all symbols have a foreground colour, symbols 19-25 also take a
+# background colour (fill)
+s + geom_point(aes(shape = z), size = 4, colour = "Red")
+s + geom_point(aes(shape = z), size = 4, colour = "Red", fill = "Black")}
Please sign in to comment.
Something went wrong with that request. Please try again.