Permalink
Browse files

Merge branch 'develop' into feature/new-guides-with-gtable

Conflicts:
	R/scale-identity.r
	R/theme-defaults.r
  • Loading branch information...
2 parents 9c6cfdd + e0dd289 commit a2cb51c85a48e4c1ea52648fdd96653e0d334336 @kohske kohske committed Jun 29, 2011
Showing with 1,224 additions and 270 deletions.
  1. +2 −2 DESCRIPTION
  2. +4 −0 NEWS
  3. +59 −0 R/aes-colour-fill-alpha.r
  4. +64 −0 R/aes-linetype-size-shape.r
  5. +26 −1 R/facet-grid-.r
  6. +13 −2 R/facet-wrap.r
  7. +5 −2 R/geom-abline.r
  8. +20 −2 R/geom-bar-.r
  9. +4 −1 R/geom-bar-histogram.r
  10. +10 −3 R/geom-bin2d.r
  11. +4 −1 R/geom-blank.r
  12. +16 −2 R/geom-boxplot.r
  13. +7 −2 R/geom-crossbar.r
  14. +5 −2 R/geom-error.r
  15. +7 −2 R/geom-errorh.r
  16. +10 −7 R/geom-freqpoly.r
  17. +5 −2 R/geom-hex.r
  18. +4 −1 R/geom-hline.r
  19. +4 −1 R/geom-linerange.r
  20. +13 −1 R/geom-path-.r
  21. +6 −1 R/geom-path-contour.r
  22. +7 −2 R/geom-path-density2d.r
  23. +11 −1 R/geom-path-line.r
  24. +6 −1 R/geom-path-step.r
  25. +6 −1 R/geom-point-.r
  26. +6 −1 R/geom-point-jitter.r
  27. +4 −1 R/geom-pointrange.r
  28. +4 −1 R/geom-polygon.r
  29. +6 −1 R/geom-quantile.r
  30. +4 −1 R/geom-rect.r
  31. +13 −3 R/geom-ribbon-.r
  32. +6 −1 R/geom-ribbon-density.r
  33. +4 −1 R/geom-rug.r
  34. +4 −1 R/geom-segment.r
  35. +4 −1 R/geom-smooth.r
  36. +16 −1 R/geom-text.r
  37. +4 −1 R/geom-tile.r
  38. +12 −2 R/geom-vline.r
  39. +4 −1 R/position-dodge.r
  40. +4 −1 R/position-fill.r
  41. +4 −1 R/position-identity.r
  42. +5 −2 R/position-jitter.r
  43. +9 −2 R/position-stack.r
  44. +1 −1 R/scale-brewer.r
  45. +23 −15 R/scale-identity.r
  46. +2 −0 R/scale-manual.r
  47. +6 −1 R/stat-bin.r
  48. +6 −1 R/stat-bin2d.r
  49. +6 −1 R/stat-binhex.r
  50. +6 −1 R/stat-boxplot.r
  51. +9 −3 R/stat-contour.r
  52. +6 −1 R/stat-density-2d.r
  53. +6 −1 R/stat-density.r
  54. +6 −1 R/stat-function.r
  55. +5 −1 R/stat-identity.r
  56. +6 −2 R/stat-qq.r
  57. +8 −1 R/stat-quantile.r
  58. +8 −1 R/stat-smooth.r
  59. +4 −1 R/stat-spoke.r
  60. +4 −1 R/stat-sum.r
  61. +4 −1 R/stat-summary.r
  62. +4 −1 R/stat-unique.r
  63. +16 −3 R/stat-vline.r
  64. +40 −40 R/theme-defaults.r
  65. +113 −0 R/theme.r
  66. +0 −48 R/xxx-codegen.r
  67. +0 −57 R/xxx.r
  68. +72 −0 man/aes_colour_fill_alpha.Rd
  69. +75 −0 man/aes_linetype_size_shape.Rd
  70. +27 −2 man/facet_grid.Rd
  71. +12 −1 man/facet_wrap.Rd
  72. +2 −0 man/geom_abline.Rd
  73. +2 −0 man/geom_area.Rd
  74. +17 −1 man/geom_bar.Rd
  75. +7 −1 man/geom_bin2d.Rd
  76. +2 −0 man/geom_blank.Rd
  77. +13 −2 man/geom_boxplot.Rd
  78. +3 −0 man/geom_contour.Rd
  79. +2 −0 man/geom_crossbar.Rd
  80. +2 −0 man/geom_density.Rd
  81. +3 −0 man/geom_density2d.Rd
  82. +2 −0 man/geom_errorbar.Rd
  83. +5 −1 man/geom_errorbarh.Rd
  84. +8 −6 man/geom_freqpoly.Rd
  85. +2 −0 man/geom_hex.Rd
  86. +2 −0 man/geom_histogram.Rd
  87. +2 −0 man/geom_hline.Rd
  88. +2 −0 man/geom_jitter.Rd
  89. +9 −0 man/geom_line.Rd
  90. +2 −0 man/geom_linerange.Rd
  91. +11 −1 man/geom_path.Rd
  92. +2 −0 man/geom_point.Rd
  93. +2 −0 man/geom_pointrange.Rd
  94. +2 −0 man/geom_polygon.Rd
  95. +3 −0 man/geom_quantile.Rd
  96. +2 −0 man/geom_rect.Rd
  97. +2 −0 man/geom_ribbon.Rd
  98. +2 −0 man/geom_rug.Rd
  99. +2 −0 man/geom_segment.Rd
  100. +2 −0 man/geom_smooth.Rd
  101. +2 −0 man/geom_step.Rd
  102. +10 −0 man/geom_text.Rd
  103. +2 −0 man/geom_tile.Rd
  104. +11 −2 man/geom_vline.Rd
  105. +112 −1 man/opts.Rd
  106. +1 −0 man/position_dodge.Rd
  107. +1 −0 man/position_fill.Rd
  108. +1 −0 man/position_identity.Rd
  109. +2 −1 man/position_jitter.Rd
  110. +5 −0 man/position_stack.Rd
  111. +1 −1 man/scale_colour_brewer.Rd
  112. +8 −4 man/scale_colour_identity.Rd
  113. +2 −0 man/scale_colour_manual.Rd
  114. +2 −0 man/stat_abline.Rd
  115. +2 −0 man/stat_bin.Rd
  116. +2 −0 man/stat_bin2d.Rd
  117. +2 −0 man/stat_binhex.Rd
  118. +2 −0 man/stat_boxplot.Rd
  119. +2 −0 man/stat_contour.Rd
  120. +3 −0 man/stat_density.Rd
  121. +3 −0 man/stat_density2d.Rd
  122. +2 −0 man/stat_function.Rd
  123. +2 −0 man/stat_hline.Rd
  124. +2 −0 man/stat_identity.Rd
  125. +2 −0 man/stat_qq.Rd
  126. +3 −0 man/stat_quantile.Rd
  127. +4 −0 man/stat_smooth.Rd
  128. +2 −0 man/stat_spoke.Rd
  129. +2 −0 man/stat_sum.Rd
  130. +2 −0 man/stat_summary.Rd
  131. +2 −0 man/stat_unique.Rd
  132. +2 −0 man/stat_vline.Rd
View
@@ -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'
@@ -174,9 +176,7 @@ Collate:
'utilities-table-template.r'
'utilities-table.r'
'utilities.r'
- 'xxx-codegen.r'
'xxx-digest.r'
- 'xxx.r'
'zxx.r'
'guides-.r'
'guide-legend.r'
View
4 NEWS
@@ -32,6 +32,10 @@ MINOR CHANGES
* `scale_shape` finally returns an error when you try and use it with a
continuous variable
+* `stat_contour` no longer errors if all breaks outside z range (fixes #195).
+
+* `geom_text` remove rows with missing values with warning (fixes #191)
+
DEVELOPMENT
* ggplot2 has moved away from the two (!!) homegrown documentation systems
View
@@ -0,0 +1,59 @@
+#' Colour related aesthetics: colour, fill and alpha
+#'
+#' @name aes_colour_fill_alpha
+#' @aliases colour color fill alpha
+#'
+#' This page demonstrates the usage of a sub-group
+#' of aesthetics; colour, fill and 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))
+NULL
@@ -0,0 +1,64 @@
+#' Differentiation related aesthetics: linetype, size, shape
+#'
+#' @name aes_linetype_size_shape
+#' @aliases linetype size shape
+#'
+#' This page demonstrates the usage of a sub-group
+#' of aesthetics; linetype, size and 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")
+NULL
View
@@ -19,8 +19,16 @@
#' # With two variables
#' p + facet_grid(clarity ~ cut)
#' p + facet_grid(cut ~ clarity)
-#' # p + facet_grid(cut ~ clarity, margins=TRUE)
+#' p + facet_grid(cut ~ clarity, margins=TRUE)
#'
+#' # To change plot order of facet grid,
+#' # change the order of varible levels with factor()
+#' diamonds$cut <- factor(diamonds$cut, levels = c("Ideal", "Very Good", "Fair", "Good", "Premium"))
+#' # Repeat first example with new order
+#' p <- ggplot(diamonds, aes(carat, ..density..)) +
+#' geom_histogram(binwidth = 1)
+#' p + facet_grid(. ~ cut)
+#'
#' qplot(mpg, wt, data=mtcars, facets = . ~ vs + am)
#' qplot(mpg, wt, data=mtcars, facets = vs + am ~ . )
#'
@@ -79,6 +87,23 @@
#' manufacturer <- reorder(manufacturer, cty)
#' })
#' last_plot() %+% mpg + opts(strip.text.y = theme_text())
+#'
+#' # Use as.table to to control direction of horizontal facets, TRUE by default
+#' h <- ggplot(mtcars, (aes(x = mpg, y = wt))) + geom_point()
+#' h + facet_grid(cyl ~ vs)
+#' h + facet_grid(cyl ~ vs, as.table = FALSE)
+#'
+#' # Use labeller to control facet labels, label_value is default
+#' h + facet_grid(cyl ~ vs, labeller = label_both)
+#' # Using label_parsed, see ?plotmath for more options
+#' mtcars$cyl2 <- factor(mtcars$cyl, labels = c("alpha", "beta", "sqrt(x, y)"))
+#' k <- qplot(wt, mpg, data = mtcars)
+#' 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)))
facet_grid <- function(facets, margins = FALSE, scales = "fixed", space = "fixed", shrink = TRUE, labeller = "label_value", as.table = TRUE) {
scales <- match.arg(scales, c("fixed", "free_x", "free_y", "free"))
free <- list(
View
@@ -19,6 +19,14 @@
#' # plots into 2d - the ribbon just gets longer
#' # d + facet_wrap(~ color + cut)
#'
+#' # To change plot order of facet wrap,
+#' # change the order of varible levels with factor()
+#' diamonds$color <- factor(diamonds$color, levels = c("G", "J", "D", "E", "I", "F", "H"))
+#' # Repeat first example with new order
+#' d <- ggplot(diamonds, aes(carat, price, fill = ..density..)) +
+#' xlim(0, 2) + stat_binhex(na.rm = TRUE) + opts(aspect.ratio = 1)
+#' d + facet_wrap(~ color)
+#'
#' # You can choose to keep the scales constant across all panels
#' # or vary the x scale, the y scale or both:
#' p <- qplot(price, data = diamonds, geom = "histogram", binwidth = 1000)
@@ -27,8 +35,11 @@
#'
#' p <- qplot(displ, hwy, data = mpg)
#' p + facet_wrap(~ cyl)
-#' p + facet_wrap(~ cyl, scales = "free")
-#'
+#' 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)
+#'
#' # Add data that does not contain all levels of the faceting variables
#' cyl6 <- subset(mpg, cyl == 6)
#' p + geom_point(data = cyl6, colour = "red", size = 1) +
View
@@ -10,8 +10,7 @@
#' (\code{geom_abline(intercept=0, slope=1)}) then the line will be the same
#' in all panels. If the intercept and slope are stored in the data, then
#' they can vary from panel to panel. See the examples for more ideas.
-#'
-#' @name geom_abline
+#'
#' @seealso \code{\link{stat_smooth}} to add lines derived from the data,
#' \code{\link{geom_hline}} for horizontal lines,
#' \code{\link{geom_vline}} for vertical lines
@@ -49,6 +48,10 @@
#' # It's actually a bit easier to do this with stat_smooth
#' p + geom_smooth(aes(group=cyl), method="lm")
#' p + geom_smooth(aes(group=cyl), method="lm", fullrange=TRUE)
+geom_abline <- function (mapping = NULL, data = NULL, stat = "abline", position = "identity", ...) {
+ GeomAbline$new(mapping = mapping, data = data, stat = stat, position = position, ...)
+}
+
GeomAbline <- proto(Geom, {
objname <- "abline"
View
@@ -28,8 +28,7 @@
#' Naomi Robbins has a nice
#' \href{http://www.b-eye-network.com/view/index.php?cid=2468}{article on this topic}.
#' This is the reason it doesn't make sense to use a log-scaled y axis with a bar chart
-#'
-#' @name geom_bar
+#'
#' @seealso \code{\link{stat_bin}} for more details of the binning alogirithm,
#' \code{\link{position_dodge}} for creating side-by-side barcharts,
#' \code{\link{position_stack}} for more info on stacking,
@@ -39,6 +38,7 @@
#' c <- ggplot(mtcars, aes(factor(cyl)))
#'
#' c + geom_bar()
+#' c + geom_bar(width=.5)
#' c + geom_bar() + coord_flip()
#' c + geom_bar(fill="white", colour="darkgreen")
#'
@@ -88,6 +88,24 @@
#' qplot(cut, meanprice)
#' qplot(cut, meanprice, geom="bar", stat="identity")
#' qplot(cut, meanprice, geom="bar", stat="identity", fill = I("grey50"))
+#'
+#' # Another stacked bar chart example
+#' k <- ggplot(mpg, aes(manufacturer, fill=class))
+#' k + geom_bar()
+#' # Use scales to change aesthetics defaults
+#' k + geom_bar() + scale_fill_brewer()
+#' k + geom_bar() + scale_fill_grey()
+#'
+#' # To change plot order of class varible
+#' # use factor() to change order of levels
+#' mpg$class <- factor(mpg$class, levels = c("midsize", "minivan",
+#' "suv", "compact", "2seater", "subcompact", "pickup"))
+#' m <- ggplot(mpg, aes(manufacturer, fill=class))
+#' m + geom_bar()
+geom_bar <- function (mapping = NULL, data = NULL, stat = "bin", position = "stack", ...) {
+ GeomBar$new(mapping = mapping, data = data, stat = stat, position = position, ...)
+}
+
GeomBar <- proto(Geom, {
objname <- "bar"
View
@@ -9,7 +9,6 @@
#' may need to look at a few to uncover the full story behind your data.
#'
#'
-#' @name geom_histogram
#' @export
#' @examples
#' # Simple examples
@@ -104,6 +103,10 @@
#' # Which looks better when the distributions are more distinct
#' ggplot(diamonds, aes(depth, fill = cut)) +
#' geom_density(alpha = 0.2) + xlim(55, 70)
+geom_histogram <- function (mapping = NULL, data = NULL, stat = "bin", position = "stack", ...) {
+ GeomHistogram$new(mapping = mapping, data = data, stat = stat, position = position, ...)
+}
+
GeomHistogram <- proto(GeomBar, {
objname <- "histogram"
View
@@ -1,9 +1,16 @@
#' Add heatmap of 2d bin counts.
-#'
-#' @name geom_bin2d
+#'
#' @export
#' @examples
-#' # See ?stat_bin2d for examples
+#' d <- ggplot(diamonds, aes(x = x, y = y)) + xlim(4,10) + ylim(4,10)
+#' d + geom_bin2d()
+#' d + geom_bin2d(binwidth = c(0.1, 0.1))
+#'
+#' # See ?stat_bin2d for more examples
+geom_bin2d <- function (mapping = NULL, data = NULL, stat = "bin2d", position = "identity", ...) {
+ GeomBin2d$new(mapping = mapping, data = data, stat = stat, position = position, ...)
+}
+
GeomBin2d <- proto(Geom, {
draw <- function(., data, scales, coordinates, ...) {
GeomRect$draw(data, scales, coordinates, ...)
View
@@ -3,11 +3,14 @@
#' The blank geom draws nothing, but can be a useful way of ensuring common
#' scales between different plots.
#'
-#' @name geom_blank
#' @export
#' @examples
#' qplot(length, rating, data=movies, geom="blank")
#' # Nothing to see here!
+geom_blank <- function (mapping = NULL, data = NULL, stat = "identity", position = "identity", ...) {
+ GeomBlank$new(mapping = mapping, data = data, stat = stat, position = position, ...)
+}
+
GeomBlank <- proto(Geom, {
objname <- "blank"
View
@@ -1,6 +1,5 @@
#' Box and whiskers plot.
#'
-#' @name geom_boxplot
#' @seealso \code{\link{stat_quantile}} to view quantiles conditioned on a
#' continuous variable, \code{\link{geom_jitter}} for another way to look
#' at conditional distributions"
@@ -30,7 +29,7 @@
#' p + geom_boxplot(aes(fill = factor(am)))
#'
#' # Set aesthetics to fixed value
-#' p + geom_boxplot(fill="grey80", colour="#3366FF")
+#' p + geom_boxplot(fill = "grey80", colour = "#3366FF")
#' qplot(factor(cyl), mpg, data = mtcars, geom = "boxplot",
#' colour = I("#3366FF"))
#'
@@ -50,6 +49,21 @@
#' qplot(year, budget, data = movies, geom = "boxplot")
#' qplot(year, budget, data = movies, geom = "boxplot",
#' group = round_any(year, 10, floor))
+#'
+#' # Using precomputed statistics
+#' # generate sample data
+#' abc <- adply(matrix(rnorm(100), ncol = 5), 2, quantile, c(0, .25, .5, .75, 1))
+#' b <- ggplot(abc, aes(x = X1, ymin = `0%`, lower = `25%`, middle = `50%`, upper = `75%`, ymax = `100%`))
+#' b + geom_boxplot(stat = "identity")
+#' b + geom_boxplot(stat = "identity") + coord_flip()
+#' b + geom_boxplot(aes(fill = X1), stat = "identity")
+geom_boxplot <- function (mapping = NULL, data = NULL, stat = "boxplot", position = "dodge",
+outlier.colour = "black", outlier.shape = 16, outlier.size = 2, ...) {
+ GeomBoxplot$new(mapping = mapping, data = data, stat = stat,
+ position = position, outlier.colour = outlier.colour, outlier.shape = outlier.shape,
+ outlier.size = outlier.size, ...)
+}
+
GeomBoxplot <- proto(Geom, {
objname <- "boxplot"
Oops, something went wrong.

0 comments on commit a2cb51c

Please sign in to comment.