Skip to content

Commit f9304b3

Browse files
committed
Add examples for continuous brewer palettes
1 parent d107718 commit f9304b3

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

R/scale-brewer.r

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@
3939
#' ggplot(diamonds, aes(x=price, fill=cut)) +
4040
#' geom_histogram(position="dodge", binwidth=1000) +
4141
#' scale_fill_brewer()
42+
#'
43+
#' # Generate map data
44+
#' library(reshape2) # for melt
45+
#' volcano3d <- melt(volcano)
46+
#' names(volcano3d) <- c("x", "y", "z")
47+
#'
48+
#' # Basic plot
49+
#' v <- ggplot() + geom_tile(aes(x=x, y=y, fill=z), data=volcano3d)
50+
#' v
51+
#' v + scale_fill_distiller()
52+
#' v + scale_fill_distiller(palette=2)
53+
#' v + scale_fill_distiller(type="div")
54+
#' v + scale_fill_distiller(palette="Spectral")
55+
#' v + scale_fill_distiller(palette="Spectral", trans="reverse")
56+
#' v + scale_fill_distiller(type="qual")
57+
#' # Not appropriate for continuous data, issues a warning
4258
scale_colour_brewer <- function(..., type = "seq", palette = 1) {
4359
discrete_scale("colour", "brewer", brewer_pal(type, palette), ...)
4460
}

man/scale_brewer.Rd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ d + scale_colour_brewer(palette="Set1")
7474
ggplot(diamonds, aes(x=price, fill=cut)) +
7575
geom_histogram(position="dodge", binwidth=1000) +
7676
scale_fill_brewer()
77+
78+
# Generate map data
79+
library(reshape2) # for melt
80+
volcano3d <- melt(volcano)
81+
names(volcano3d) <- c("x", "y", "z")
82+
83+
# Basic plot
84+
v <- ggplot() + geom_tile(aes(x=x, y=y, fill=z), data=volcano3d)
85+
v
86+
v + scale_fill_distiller()
87+
v + scale_fill_distiller(palette=2)
88+
v + scale_fill_distiller(type="div")
89+
v + scale_fill_distiller(palette="Spectral")
90+
v + scale_fill_distiller(palette="Spectral", trans="reverse")
91+
v + scale_fill_distiller(type="qual")
92+
# Not appropriate for continuous data, issues a warning
7793
}
7894
\seealso{
7995
Other colour scales: \code{\link{scale_color_continuous}},

0 commit comments

Comments
 (0)