Permalink
Browse files

More example fixes

  • Loading branch information...
1 parent d4845c8 commit 16c0e55767ef493df9779e928aa2846d3bb5525f @hadley hadley committed Dec 29, 2011
Showing with 72 additions and 45 deletions.
  1. +1 −1 R/facet-grid-.r
  2. +1 −1 R/facet-null.r
  3. +1 −1 R/facet-wrap.r
  4. +1 −1 R/geom-linerange.r
  5. +1 −0 R/geom-map.r
  6. +1 −0 R/geom-path-.r
  7. +2 −1 R/geom-path-line.r
  8. +1 −1 R/geom-path-step.r
  9. +1 −0 R/geom-ribbon-.r
  10. +1 −1 R/geom-text.r
  11. +1 −0 R/geom-tile.r
  12. +1 −0 R/geom-violin.r
  13. +1 −1 R/guide-colorbar.r
  14. +3 −3 R/guide-legend.r
  15. +1 −1 R/layer.r
  16. +1 −3 R/scale-brewer.r
  17. +2 −1 R/scale-continuous.r
  18. +2 −0 R/scale-date.r
  19. +2 −0 R/scale-datetime.r
  20. +1 −1 R/scale-gradient.r
  21. +1 −0 R/scale-gradient2.r
  22. +1 −1 R/scale-grey.r
  23. +1 −1 R/scale-hue.r
  24. +2 −2 R/scale-linetype.r
  25. +1 −0 R/stat-contour.r
  26. +1 −0 R/stat-density.r
  27. +1 −1 R/stat-smooth.r
  28. +1 −1 R/stat-summary-hex.r
  29. +2 −1 R/summary.r
  30. +1 −0 R/theme.r
  31. +1 −1 man/facet_wrap.Rd
  32. +2 −1 man/geom_line.Rd
  33. +1 −1 man/geom_linerange.Rd
  34. +1 −0 man/geom_map.Rd
  35. +1 −0 man/geom_path.Rd
  36. +1 −0 man/geom_ribbon.Rd
  37. +1 −1 man/geom_step.Rd
  38. +1 −1 man/geom_text.Rd
  39. +1 −0 man/geom_tile.Rd
  40. +1 −0 man/geom_violin.Rd
  41. +1 −1 man/guide_colourbar.Rd
  42. +3 −3 man/guide_legend.Rd
  43. +1 −0 man/opts.Rd
  44. +1 −3 man/scale_brewer.Rd
  45. +2 −1 man/scale_continuous.Rd
  46. +2 −0 man/scale_date.Rd
  47. +2 −0 man/scale_datetime.Rd
  48. +1 −1 man/scale_gradient.Rd
  49. +1 −0 man/scale_gradient2.Rd
  50. +1 −1 man/scale_grey.Rd
  51. +1 −1 man/scale_hue.Rd
  52. +2 −2 man/scale_linetype.Rd
  53. +1 −0 man/stat_contour.Rd
  54. +1 −0 man/stat_density.Rd
  55. +1 −1 man/stat_smooth.Rd
  56. +1 −1 man/stat_summary_hex.Rd
  57. +1 −1 man/summary.ggplot.Rd
View
@@ -329,7 +329,7 @@ facet_panels.grid <- function(facet, panel, coord, theme, geom_grobs) {
gTree(children = do.call("gList", panel_grobs))
})
- panel_matrix <- matrix(panel_grobs, nrow = nrow, ncol = ncol, byrow = T)
+ panel_matrix <- matrix(panel_grobs, nrow = nrow, ncol = ncol, byrow = TRUE)
size <- function(x) unit(diff(scale_dimension(x)), "null")
View
@@ -52,7 +52,7 @@ facet_render.null <- function(facet, panel, coord, theme, geom_grobs) {
all <- matrix(list(
axis_v, panel_grob,
zeroGrob(), axis_h
- ), ncol = 2, byrow = T)
+ ), ncol = 2, byrow = TRUE)
layout <- layout_matrix("layout", all,
widths = unit.c(grobWidth(axis_v), unit(1, "null")),
View
@@ -40,7 +40,7 @@
#' p + facet_wrap(~ cyl, scales = "free")
#'
#' # Use as.table to to control direction of horizontal facets, TRUE by default
-#' p + facet_wrap(~ cyl, as.table = F)
+#' p + facet_wrap(~ cyl, as.table = FALSE)
#'
#' # Add data that does not contain all levels of the faceting variables
#' cyl6 <- subset(mpg, cyl == 6)
View
@@ -11,7 +11,7 @@
#' # Generate data: means and standard errors of means for prices
#' # for each type of cut
#' dmod <- lm(price ~ cut, data=diamonds)
-#' cuts <- data.frame(cut=unique(diamonds$cut), predict(dmod, data.frame(cut = unique(diamonds$cut)), se=T)[c("fit","se.fit")])
+#' cuts <- data.frame(cut=unique(diamonds$cut), predict(dmod, data.frame(cut = unique(diamonds$cut)), se=TRUE)[c("fit","se.fit")])
#'
#' qplot(cut, fit, data=cuts)
#' # With a bar chart, we are comparing lengths, so the y-axis is
View
@@ -43,6 +43,7 @@ NULL
#'
#' # Better example
#' crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
+#' library(reshape2) # for melt
#' crimesm <- melt(crimes, id = 1)
#' if (require(maps)) {
#' states_map <- map_data("state")
View
@@ -83,6 +83,7 @@
#'
#' # Use the arrow parameter to add an arrow to the line
#' # See ?grid::arrow for more details
+#' library(grid)
#' c <- ggplot(economics, aes(x = date, y = pop))
#' # Arrow defaults to "last"
#' c + geom_path(arrow = arrow())
View
@@ -39,6 +39,7 @@
#' # See ?grid::arrow for more details
#' c <- ggplot(economics, aes(x = date, y = pop))
#' # Arrow defaults to "last"
+#' library(grid)
#' c + geom_line(arrow = arrow())
#' c + geom_line(arrow = arrow(angle = 15, ends = "both", type = "closed"))
#'
@@ -52,7 +53,7 @@
#' group <- rep(LETTERS[1:3], each = 100)
#'
#' df <- data.frame(id = seq_along(group), group, y2005, y2010)
-#' library(reshape2)
+#' library(reshape2) # for melt
#' dfm <- melt(df, id.var = c("id", "group"))
#' ggplot(dfm, aes(variable, value, group = id, colour = group)) +
#' geom_path(alpha = 0.5)
View
@@ -19,7 +19,7 @@
#' # Also works with other aesthetics
#' df <- data.frame(
#' x = sort(rnorm(50)),
-#' trt = sample(c("a", "b"), 50, rep = T)
+#' trt = sample(c("a", "b"), 50, rep = TRUE)
#' )
#' qplot(seq_along(x), x, data = df, geom="step", colour = trt)
geom_step <- function (mapping = NULL, data = NULL, stat = "identity", position = "identity",
View
@@ -9,6 +9,7 @@
#' @examples
#' # Generate data
#' huron <- data.frame(year = 1875:1972, level = as.vector(LakeHuron))
+#' library(plyr) # to access round_any
#' huron$decade <- round_any(huron$year, 10, floor)
#'
#' h <- ggplot(huron, aes(x=year))
View
@@ -28,7 +28,7 @@
#' # details of the display are described in ?plotmath, but note that
#' # geom_text uses strings, not expressions.
#' p + geom_text(aes(label = paste(wt, "^(", cyl, ")", sep = "")),
-#' parse = T)
+#' parse = TRUE)
#'
#' # Add an annotation not from a variable source
#' c <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
View
@@ -33,6 +33,7 @@
#'
#' # Input that works with image
#' image(t(volcano)[ncol(volcano):1,])
+#' library(reshape2) # for melt
#' ggplot(melt(volcano), aes(x=Var1, y=Var2, fill=value)) + geom_tile()
#'
#' # inspired by the image-density plots of Ken Knoblauch
View
@@ -44,6 +44,7 @@
#' # Scale transformations occur before the density statistics are computed.
#' # Coordinate transformations occur afterwards. Observe the effect on the
#' # number of outliers.
+#' library(plyr) # to access round_any
#' m <- ggplot(movies, aes(y = votes, x = rating,
#' group = round_any(rating, 0.5)))
#' m + geom_violin()
View
@@ -39,7 +39,7 @@
#' @seealso \code{\link{guides}}, \code{\link{guide_legend}}
#' @export
#' @examples
-#' library(reshape2)
+#' library(reshape2) # for melt
#' df <- melt(outer(1:4, 1:4), varnames = c("X1", "X2"))
#'
#' p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value))
View
@@ -56,7 +56,7 @@
#' @seealso \code{\link{guides}}, \code{\link{guide_colorbar}}
#' @export
#' @examples
-#' library(reshape2)
+#' library(reshape2) # for melt
#' df <- melt(outer(1:4, 1:4), varnames = c("X1", "X2"))
#'
#' p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value))
@@ -108,8 +108,8 @@
#' p <- qplot(1:20, 1:20, colour = letters[1:20])
#' p + guides(col = guide_legend(nrow = 8))
#' p + guides(col = guide_legend(ncol = 8))
-#' p + guides(col = guide_legend(nrow = 8, byrow = T))
-#' p + guides(col = guide_legend(ncol = 8, byrow = T))
+#' p + guides(col = guide_legend(nrow = 8, byrow = TRUE))
+#' p + guides(col = guide_legend(ncol = 8, byrow = TRUE))
#'
#' # reversed order legend
#' p + guides(col = guide_legend(reverse = TRUE))
View
@@ -254,7 +254,7 @@ layer <- Layer$new
# Determine if aesthetic is calculated
is_calculated_aes <- function(aesthetics) {
match <- "\\.\\.([a-zA-z._]+)\\.\\."
- stats <- rep(F, length(aesthetics))
+ stats <- rep(FALSE, length(aesthetics))
grepl(match, sapply(aesthetics, deparse))
}
View
@@ -16,12 +16,10 @@
#' d + scale_colour_brewer("clarity")
#' d + scale_colour_brewer(expression(clarity[beta]))
#'
-#' # Select brewer palette to use, see ?brewer.pal for more details
+#' # Select brewer palette to use, see ?scales::brewer_pal for more details
#' d + scale_colour_brewer(type="seq")
#' d + scale_colour_brewer(type="seq", palette=3)
#'
-#' RColorBrewer::display.brewer.all(n=8, exact.n=FALSE)
-#'
#' d + scale_colour_brewer(palette="Blues")
#' d + scale_colour_brewer(palette="Set1")
#'
@@ -10,7 +10,8 @@
#' @rdname scale_continuous
#' @export
#' @examples
-#' (m <- qplot(rating, votes, data=subset(movies, votes > 1000), na.rm = T))
+#' (m <- qplot(rating, votes, data=subset(movies, votes > 1000),
+#' na.rm = TRUE))
#'
#' # Manipulating the default position scales lets you:
#'
View
@@ -16,6 +16,7 @@
#' # We can control the format of the labels, and the frequency of
#' # the major and minor tickmarks. See ?format.Date and ?seq.Date
#' # for more details.
+#' library(scales) # to access breaks/formatting functions
#' dt + scale_x_date()
#' dt + scale_x_date(labels = date_format("%m/%d"))
#' dt + scale_x_date(labels = date_format("%W"))
@@ -49,6 +50,7 @@
#' # If we want to display multiple series, one for each variable
#' # it's easiest to first change the data from a "wide" to a "long"
#' # format:
+#' library(reshape2) # for melt
#' em <- melt(economics, id = "date")
#'
#' # Then we can group and facet by the new "variable" variable
View
@@ -33,8 +33,10 @@
#'
#' # Manual scale selection
#' qplot(day30, y, data = df)
+#' library(scales) # to access breaks/formatting functions
#' last_plot() + scale_x_datetime(breaks = date_breaks("2 weeks"))
#' last_plot() + scale_x_datetime(breaks = date_breaks("10 days"))
+#' library(scales) # to access breaks/formatting functions
#' last_plot() + scale_x_datetime(breaks = date_breaks("10 days"),
#' labels = date_format("%d/%m"))
scale_x_datetime <- function(..., expand = c(0.05, 0)) {
View
@@ -49,7 +49,7 @@
#' h + scale_fill_continuous(low="black", high="pink", limits=c(0,3100))
#'
#' # Colour of missing values is controlled with na.value:
-#' miss <- sample(c(NA, 1:5), nrow(mtcars), rep = T)
+#' miss <- sample(c(NA, 1:5), nrow(mtcars), rep = TRUE)
#' qplot(mpg, wt, data = mtcars, colour = miss)
#' qplot(mpg, wt, data = mtcars, colour = miss) +
#' scale_colour_gradient(na.value = "black")
View
@@ -22,6 +22,7 @@
#'
#' # Using "muted" colours makes for pleasant graphics
#' # (and they have better perceptual properties too)
+#' library(scales) # for muted
#' d + scale_colour_gradient2(low="red", high="blue")
#' d + scale_colour_gradient2(low=muted("red"), high=muted("blue"))
#'
View
@@ -16,7 +16,7 @@
#' p + scale_colour_grey() + theme_bw()
#'
#' # Colour of missing values is controlled with na.value:
-#' miss <- factor(sample(c(NA, 1:5), nrow(mtcars), rep = T))
+#' miss <- factor(sample(c(NA, 1:5), nrow(mtcars), rep = TRUE))
#' qplot(mpg, wt, data = mtcars, colour = miss) + scale_colour_grey()
#' qplot(mpg, wt, data = mtcars, colour = miss) +
#' scale_colour_grey(na.value = "green")
View
@@ -36,7 +36,7 @@
#' d + geom_point(alpha = 0.2)
#'
#' # Colour of missing values is controlled with na.value:
-#' miss <- factor(sample(c(NA, 1:5), nrow(mtcars), rep = T))
+#' miss <- factor(sample(c(NA, 1:5), nrow(mtcars), rep = TRUE))
#' qplot(mpg, wt, data = mtcars, colour = miss)
#' qplot(mpg, wt, data = mtcars, colour = miss) +
#' scale_colour_hue(na.value = "black")
View
@@ -8,8 +8,8 @@
#' @rdname scale_linetype
#' @export
#' @examples
-#' library(reshape2)
-#' library(plyr)
+#' library(reshape2) # for melt
+#' library(plyr) # for ddply
#' ecm <- melt(economics, id = "date")
#' rescale01 <- function(x) (x - min(x)) / diff(range(x))
#' ecm <- ddply(ecm, "variable", transform, value = rescale01(value))
View
@@ -8,6 +8,7 @@
#' @export
#' @examples
#' # Generate data
+#' library(reshape2) # for melt
#' volcano3d <- melt(volcano)
#' names(volcano3d) <- c("x", "y", "z")
#'
View
@@ -73,6 +73,7 @@
#' m <- ggplot(movies, aes(x=rating, weight=votes/sum(votes)))
#' m + geom_histogram(aes(y=..density..)) + geom_density(fill=NA, colour="black")
#'
+#' library(plyr) # to access round_any
#' movies$decade <- round_any(movies$year, 10)
#' m <- ggplot(movies, aes(x=rating, colour=decade, group=decade))
#' m + geom_density(fill=NA)
View
@@ -68,7 +68,7 @@
#' # Smoothers for subsets
#' c <- ggplot(mtcars, aes(y=wt, x=mpg)) + facet_grid(. ~ cyl)
#' c + stat_smooth(method=lm) + geom_point()
-#' c + stat_smooth(method=lm, fullrange=T) + geom_point()
+#' c + stat_smooth(method=lm, fullrange = TRUE) + geom_point()
#'
#' # Geoms and stats are automatically split by aesthetics that are factors
#' c <- ggplot(mtcars, aes(y=wt, x=mpg, colour=factor(cyl)))
@@ -25,7 +25,7 @@
##'
##' # Specifying function
##' d + stat_summary_hex(fun = function(x) sum(x^2))
-##' d + stat_summary_hex(fun = var, na.rm = T)
+##' d + stat_summary_hex(fun = var, na.rm = TRUE)
stat_summary_hex <- function (mapping = NULL, data = NULL, geom = "hex", position = "identity",
bins = 30, drop = TRUE, fun = mean, ...) {
View
@@ -3,7 +3,8 @@
#' @param object ggplot2 object to summarise
#' @param ... other arguments ignored (for compatibility with generic)
#' @keywords internal
-#' @S3method summary ggplot
+#' @method summary ggplot
+#' @export
#' @examples
#' summary(qplot(mpg, wt, data=mtcars))
summary.ggplot <- function(object, ...) {
View
@@ -150,6 +150,7 @@ theme_set <- .theme$set
#' m + theme_bw()
#'
#' # Manipulate Axis Attributes
+#' library(grid) # for unit
#' m + opts(axis.line = theme_segment())
#' m + opts(axis.line = theme_segment(colour = "red", linetype = "dotted"))
#' m + opts(axis.text.x = theme_text(colour = "blue"))
View
@@ -67,7 +67,7 @@ p + facet_wrap(~ cyl)
p + facet_wrap(~ cyl, scales = "free")
# Use as.table to to control direction of horizontal facets, TRUE by default
-p + facet_wrap(~ cyl, as.table = F)
+p + facet_wrap(~ cyl, as.table = FALSE)
# Add data that does not contain all levels of the faceting variables
cyl6 <- subset(mpg, cyl == 6)
View
@@ -62,6 +62,7 @@ qplot(date, pop, data=economics, size=unemploy/pop, geom="line")
# See ?grid::arrow for more details
c <- ggplot(economics, aes(x = date, y = pop))
# Arrow defaults to "last"
+library(grid)
c + geom_line(arrow = arrow())
c + geom_line(arrow = arrow(angle = 15, ends = "both", type = "closed"))
@@ -75,7 +76,7 @@ y2010 <- y2005 * runif(300, -1.05, 1.5)
group <- rep(LETTERS[1:3], each = 100)
df <- data.frame(id = seq_along(group), group, y2005, y2010)
-library(reshape2)
+library(reshape2) # for melt
dfm <- melt(df, id.var = c("id", "group"))
ggplot(dfm, aes(variable, value, group = id, colour = group)) +
geom_path(alpha = 0.5)
@@ -32,7 +32,7 @@
# Generate data: means and standard errors of means for prices
# for each type of cut
dmod <- lm(price ~ cut, data=diamonds)
-cuts <- data.frame(cut=unique(diamonds$cut), predict(dmod, data.frame(cut = unique(diamonds$cut)), se=T)[c("fit","se.fit")])
+cuts <- data.frame(cut=unique(diamonds$cut), predict(dmod, data.frame(cut = unique(diamonds$cut)), se=TRUE)[c("fit","se.fit")])
qplot(cut, fit, data=cuts)
# With a bar chart, we are comparing lengths, so the y-axis is
View
@@ -63,6 +63,7 @@ ggplot(values, aes(fill = value)) +
# Better example
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
+library(reshape2) # for melt
crimesm <- melt(crimes, id = 1)
if (require(maps)) {
states_map <- map_data("state")
View
@@ -118,6 +118,7 @@ should_stop(p + geom_line(aes(colour = x), linetype=2))
# Use the arrow parameter to add an arrow to the line
# See ?grid::arrow for more details
+library(grid)
c <- ggplot(economics, aes(x = date, y = pop))
# Arrow defaults to "last"
c + geom_path(arrow = arrow())
View
@@ -36,6 +36,7 @@
\examples{
# Generate data
huron <- data.frame(year = 1875:1972, level = as.vector(LakeHuron))
+library(plyr) # to access round_any
huron$decade <- round_any(huron$year, 10, floor)
h <- ggplot(huron, aes(x=year))
View
@@ -46,7 +46,7 @@ plot(x, type = "S")
# Also works with other aesthetics
df <- data.frame(
x = sort(rnorm(50)),
- trt = sample(c("a", "b"), 50, rep = T)
+ trt = sample(c("a", "b"), 50, rep = TRUE)
)
qplot(seq_along(x), x, data = df, geom="step", colour = trt)
}
View
@@ -55,7 +55,7 @@ p + geom_text(aes(size=wt)) + scale_size(range=c(3,6))
# details of the display are described in ?plotmath, but note that
# geom_text uses strings, not expressions.
p + geom_text(aes(label = paste(wt, "^(", cyl, ")", sep = "")),
- parse = T)
+ parse = TRUE)
# Add an annotation not from a variable source
c <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
View
@@ -58,6 +58,7 @@ p + geom_tile()
# Input that works with image
image(t(volcano)[ncol(volcano):1,])
+library(reshape2) # for melt
ggplot(melt(volcano), aes(x=Var1, y=Var2, fill=value)) + geom_tile()
# inspired by the image-density plots of Ken Knoblauch
View
@@ -75,6 +75,7 @@ qplot(factor(cyl), mpg, data = mtcars, geom = "violin",
# Scale transformations occur before the density statistics are computed.
# Coordinate transformations occur afterwards. Observe the effect on the
# number of outliers.
+library(plyr) # to access round_any
m <- ggplot(movies, aes(y = votes, x = rating,
group = round_any(rating, 0.5)))
m + geom_violin()
@@ -123,7 +123,7 @@
\code{\link{guides}}.
}
\examples{
-library(reshape2)
+library(reshape2) # for melt
df <- melt(outer(1:4, 1:4), varnames = c("X1", "X2"))
p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value))
Oops, something went wrong.

0 comments on commit 16c0e55

Please sign in to comment.