-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
153 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")} |