# tidyverse/ggplot2

Checking examples. Up to geom_blank.Rd

Showing with 32 additions and 20 deletions.
1. +11 −6 R/aes-linetype-size-shape.r
2. +2 −2 R/facet-grid-.r
3. +1 −0 R/geom-boxplot.r
4. +2 −2 R/quick-plot.r
5. +11 −6 man/aes_linetype_size_shape.Rd
6. +2 −2 man/facet_grid.Rd
7. +1 −0 man/geom_boxplot.Rd
8. +2 −2 man/qplot.Rd
 @@ -24,7 +24,12 @@ #' f + geom_line(linetype = "3313") #' #' # Mapping line type from a variable -#' ec_scaled <- data.frame(date = economics\$date, rescaler(economics[, -(1:2)], "range")) +#' library(plyr) +#' library(reshape2) +#' rescale01 <- function(x) (x - min(x)) / diff(range(x)) +#' ec_scaled <- data.frame( +#' date = economics\$date, +#' colwise(rescale01)(economics[, -(1:2)])) #' ecm <- melt(ec_scaled, id = "date") #' qplot(date, value, data = ecm, geom = "line", linetype = variable) #' @@ -49,15 +54,15 @@ #' #' # 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) +#' s + geom_point(aes(shape = z), size = 4) + scale_shape_identity() #' # 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") +#' s + geom_point(aes(shape = z), size = 4, colour = "Red") + +#' scale_shape_identity() +#' s + geom_point(aes(shape = z), size = 4, colour = "Red", fill = "Black") + +#' scale_shape_identity() NULL
 @@ -125,8 +125,8 @@ #' k + facet_grid(. ~ cyl2, labeller = label_parsed) #' # For label_bquote the label value is x. #' p <- qplot(wt, mpg, data = mtcars) -#' p + facet_grid(~ vs, labeller = label_bquote(alpha ^ .(x))) -#' p + facet_grid(~ vs, labeller = label_bquote(.(x) ^ .(x))) +#' p + facet_grid(. ~ vs, labeller = label_bquote(alpha ^ .(x))) +#' p + facet_grid(. ~ vs, labeller = label_bquote(.(x) ^ .(x))) facet_grid <- function(facets, margins = FALSE, scales = "fixed", space = "fixed", shrink = TRUE, labeller = "label_value", as.table = TRUE, drop = TRUE) { scales <- match.arg(scales, c("fixed", "free_x", "free_y", "free")) free <- list(
 @@ -62,6 +62,7 @@ #' # Scale transformations occur before the boxplot 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_boxplot()
 @@ -61,8 +61,8 @@ #' qplot(y = mpg, data = mtcars) #' #' # Use different geoms -#' qplot(mpg, wt, geom="path") -#' qplot(factor(cyl), wt, geom=c("boxplot", "jitter")) +#' qplot(mpg, wt, data = mtcars, geom="path") +#' qplot(factor(cyl), wt, data = mtcars, geom=c("boxplot", "jitter")) qplot <- function(x, y = NULL, ..., data, facets = NULL, margins=FALSE, geom = "auto", stat=list(NULL), position=list(NULL), xlim = c(NA, NA), ylim = c(NA, NA), log = "", main = NULL, xlab = deparse(substitute(x)), ylab = deparse(substitute(y)), asp = NA) { argnames <- names(as.list(match.call(expand.dots=FALSE)[-1]))
 @@ -25,7 +25,12 @@ f + geom_line(linetype = "dotdash") f + geom_line(linetype = "3313") # Mapping line type from a variable -ec_scaled <- data.frame(date = economics\$date, rescaler(economics[, -(1:2)], "range")) +library(plyr) +library(reshape2) +rescale01 <- function(x) (x - min(x)) / diff(range(x)) +ec_scaled <- data.frame( + date = economics\$date, + colwise(rescale01)(economics[, -(1:2)])) ecm <- melt(ec_scaled, id = "date") qplot(date, value, data = ecm, geom = "line", linetype = variable) @@ -50,16 +55,16 @@ 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) +s + geom_point(aes(shape = z), size = 4) + scale_shape_identity() # 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") +s + geom_point(aes(shape = z), size = 4, colour = "Red") + + scale_shape_identity() +s + geom_point(aes(shape = z), size = 4, colour = "Red", fill = "Black") + + scale_shape_identity() }
 @@ -151,7 +151,7 @@ k + facet_grid(. ~ cyl2) k + facet_grid(. ~ cyl2, labeller = label_parsed) # For label_bquote the label value is x. p <- qplot(wt, mpg, data = mtcars) -p + facet_grid(~ vs, labeller = label_bquote(alpha ^ .(x))) -p + facet_grid(~ vs, labeller = label_bquote(.(x) ^ .(x))) +p + facet_grid(. ~ vs, labeller = label_bquote(alpha ^ .(x))) +p + facet_grid(. ~ vs, labeller = label_bquote(.(x) ^ .(x))) }
 @@ -91,6 +91,7 @@ qplot(factor(cyl), mpg, data = mtcars, geom = "boxplot", # Scale transformations occur before the boxplot 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_boxplot()
 @@ -96,7 +96,7 @@ qplot(mpg, data = mtcars) qplot(y = mpg, data = mtcars) # Use different geoms -qplot(mpg, wt, geom="path") -qplot(factor(cyl), wt, geom=c("boxplot", "jitter")) +qplot(mpg, wt, data = mtcars, geom="path") +qplot(factor(cyl), wt, data = mtcars, geom=c("boxplot", "jitter")) }