Skip to content

Commit b5a54e2

Browse files
committed
Merge remote-tracking branch 'hadley/master'
2 parents 5e7fe1e + 5726d87 commit b5a54e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+167
-57
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ visual_test
1111
^NEWS$
1212
^revdep$
1313
^\.httr-oauth$
14+
^codecov\.yml$

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: ggplot2
2-
Version: 2.1.0
2+
Version: 2.1.0.9000
33
Authors@R: c(
44
person("Hadley", "Wickham", , "[email protected]", c("aut", "cre")),
55
person("Winston", "Chang", , "[email protected]", "aut"),
@@ -23,7 +23,8 @@ Imports:
2323
plyr (>= 1.7.1),
2424
reshape2,
2525
scales (>= 0.3.0),
26-
stats
26+
stats,
27+
tibble
2728
Suggests:
2829
covr,
2930
ggplot2movies,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,4 @@ import(scales)
491491
importFrom(plyr,as.quoted)
492492
importFrom(plyr,defaults)
493493
importFrom(stats,setNames)
494+
importFrom(tibble,tibble)

NEWS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# ggplot2 2.1.0.9000
22

3+
* `stat_bin()` and `stat_summary_hex()` now accept length 1 `binwidth` (#1610)
4+
5+
* `geom_histogram()` and `stat_bin()` understand the `breaks` parameter once
6+
more. (#1665).
7+
8+
* `geom_step()` gives useful warning if only one data point in layer (#1645).
9+
10+
* Clarified needed input to `geom_contour()` (#1577).
11+
12+
* Import tibble. This ensures that all built-in datasets print compactly
13+
even if you haven't explicitly loaded tibble or dplyr (#1677).
14+
15+
* `stat_ecdf()` respects `pad` argument (#1646).
16+
317
* `x` and `y` scales are now symmetric regarding the list of
418
aesthetics they accept: `xmin_final`, `xmax_final`, `xlower`,
519
`xmiddle` and `xupper` are now valid `x` aesthetics.
@@ -17,6 +31,9 @@
1731
* Minor code formatting issues in examples and function parameters were
1832
fixed. (@hrbrmstr)
1933

34+
* Fix error message of Stats ggprotos when required aesthetics are
35+
missing.
36+
2037
# ggplot2 2.1.0
2138

2239
## New features

R/annotation.r

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
#' colour = "red", size = 1.5)
3030
#'
3131
#' p + annotate("text", x = 2:3, y = 20:21, label = c("my label", "label 2"))
32+
#'
33+
#' p + annotate("text", x = 4, y = 25, label = "italic(R) ^ 2 == 0.75",
34+
#' parse = TRUE)
35+
#' p + annotate("text", x = 4, y = 25,
36+
#' label = "paste(italic(R) ^ 2, \" = .75\")", parse = TRUE)
3237
annotate <- function(geom, x = NULL, y = NULL, xmin = NULL, xmax = NULL,
3338
ymin = NULL, ymax = NULL, xend = NULL, yend = NULL, ...,
3439
na.rm = FALSE) {

R/fortify.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Fortify a model with data.
22
#'
3-
#' Rather than using this function, I now recomend using the \pkg{broom}
3+
#' Rather than using this function, I now recommend using the \pkg{broom}
44
#' package, which implements a much wider range of methods. \code{fortify}
55
#' may be deprecated in the future.
66
#'

R/geom-bar.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#' There are two types of bar charts, determined by what is mapped to bar
44
#' height. By default, \code{geom_bar} uses \code{stat="count"} which makes the
55
#' height of the bar proportion to the number of cases in each group (or if the
6-
#' \code{weight} aethetic is supplied, the sum of the weights). If you want the
6+
#' \code{weight} aesthetic is supplied, the sum of the weights). If you want the
77
#' heights of the bars to represent values in the data, use
88
#' \code{stat="identity"} and map a variable to the \code{y} aesthetic.
99
#'

R/geom-boxplot.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#' end of the whiskers are outliers and plotted as points (as specified by Tukey).
1414
#'
1515
#' In a notched box plot, the notches extend \code{1.58 * IQR / sqrt(n)}.
16-
#' This gives a roughly 95% confidence interval for comparing medians.
16+
#' This gives a roughly 95\% confidence interval for comparing medians.
1717
#' See McGill et al. (1978) for more details.
1818
#'
1919
#' @section Aesthetics:

R/geom-contour.r

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#' Display contours of a 3d surface in 2d.
22
#'
3+
#' To be a valid surface, the most only be a single combination of each
4+
#' unique \code{x} and \code{y} aesthetics. Contouring tends to work best
5+
#' when \code{x} and \code{y} form a (roughly) evenly spaced grid.
6+
#'
37
#' @section Aesthetics:
48
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "contour")}
59
#'

R/geom-histogram.r

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@
6161
#' # bar is anchored at zero, and so when transformed becomes negative
6262
#' # infinity. This is not a problem when transforming the scales, because
6363
#' # no observations have 0 ratings.
64-
#' m + geom_histogram(origin = 0) + coord_trans(x = "log10")
65-
#' # Use origin = 0, to make sure we don't take sqrt of negative values
66-
#' m + geom_histogram(origin = 0) + coord_trans(x = "sqrt")
64+
#' m + geom_histogram(boundary = 0) + coord_trans(x = "log10")
65+
#' # Use boundary = 0, to make sure we don't take sqrt of negative values
66+
#' m + geom_histogram(boundary = 0) + coord_trans(x = "sqrt")
6767
#'
6868
#' # You can also transform the y axis. Remember that the base of the bars
6969
#' # has value 0, so log transformations are not appropriate

R/geom-path.r

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ stairstep <- function(data, direction="hv") {
298298
data <- as.data.frame(data)[order(data$x), ]
299299
n <- nrow(data)
300300

301+
if (n <= 1) {
302+
# Need at least one observation
303+
return(data[0, , drop = FALSE])
304+
}
305+
301306
if (direction == "vh") {
302307
xs <- rep(1:n, each = 2)[-2*n]
303308
ys <- c(1, rep(2:n, each = 2))

R/geom-text.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#' @param nudge_x,nudge_y Horizontal and vertical adjustment to nudge labels by.
3434
#' Useful for offsetting text from points, particularly on discrete scales.
3535
#' @param check_overlap If \code{TRUE}, text that overlaps previous text in the
36-
#' same layer will not be plotted. A quick and dirty way
36+
#' same layer will not be plotted.
3737
#' @export
3838
#' @examples
3939
#' p <- ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars)))

R/hexbin.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ hex_bounds <- function(x, binwidth) {
1313
}
1414

1515
hexBinSummarise <- function(x, y, z, binwidth, fun = mean, fun.args = list(), drop = TRUE) {
16+
if (length(binwidth) == 1) {
17+
binwidth <- rep(binwidth, 2)
18+
}
19+
1620
# Convert binwidths into bounds + nbins
1721
xbnds <- hex_bounds(x, binwidth[1])
1822
xbins <- diff(xbnds) / binwidth[1]

R/position-jitter.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#' # take up as much space as a boxplot or a bar
2828
#' ggplot(mpg, aes(class, hwy)) +
2929
#' geom_jitter() +
30-
#' geom_boxplot()
30+
#' geom_boxplot(colour = "grey50")
3131
position_jitter <- function(width = NULL, height = NULL) {
3232
ggproto(NULL, PositionJitter,
3333
width = width,

R/save.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ plot_dim <- function(dim = c(NA, NA), scale = 1, units = c("in", "cm", "mm"),
8484

8585
if (limitsize && any(dim >= 50)) {
8686
stop("Dimensions exceed 50 inches (height and width are specified in '",
87-
units, "' not pixels). If you're sure you a plot that big, use ",
87+
units, "' not pixels). If you're sure you want a plot that big, use ",
8888
"`limitsize = FALSE`.", call. = FALSE)
8989
}
9090

R/scale-gradient.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' \code{scale_*_gradientn} creats a n-colour gradient.
66
#'
77
#' Default colours are generated with \pkg{munsell} and
8-
#' \code{mnsl(c("2.5PB 2/4", "2.5PB 7/10")}. Generally, for continuous
8+
#' \code{mnsl(c("2.5PB 2/4", "2.5PB 7/10"))}. Generally, for continuous
99
#' colour scales you want to keep hue constant, but vary chroma and
1010
#' luminance. The \pkg{munsell} package makes this easy to do using the
1111
#' Munsell colour system.

R/scale-manual.r

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
#'
33
#' @name scale_manual
44
#' @inheritParams scale_x_discrete
5-
#' @param values a set of aesthetic values to map data values to. If this
5+
#' @param values a set of aesthetic values to map data values to. If this
66
#' is a named vector, then the values will be matched based on the names.
77
#' If unnamed, values will be matched in order (usually alphabetical) with
8-
#' the limits of the scale. Any data values that don't match will be
8+
#' the limits of the scale. Any data values that don't match will be
99
#' given \code{na.value}.
1010
#' @examples
1111
#' \donttest{
1212
#' p <- ggplot(mtcars, aes(mpg, wt)) +
1313
#' geom_point(aes(colour = factor(cyl)))
1414
#'
15-
#' p + scale_colour_manual(values = c("red","blue", "green"))
15+
#' p + scale_colour_manual(values = c("red", "blue", "green"))
1616
#' p + scale_colour_manual(
17-
#' values = c("8" = "red","4" = "blue","6" = "green"))
17+
#' values = c("8" = "red", "4" = "blue", "6" = "green"))
1818
#' # With rgb hex values
1919
#' p + scale_colour_manual(values = c("#FF0000", "#0000FF", "#00FF00"))
2020
#'
2121
#' # As with other scales you can use breaks to control the appearance
2222
#' # of the legend
23-
#' cols <- c("8" = "red","4" = "blue","6" = "darkgreen", "10" = "orange")
23+
#' cols <- c("8" = "red", "4" = "blue", "6" = "darkgreen", "10" = "orange")
2424
#' p + scale_colour_manual(values = cols)
2525
#' p + scale_colour_manual(values = cols, breaks = c("4", "6", "8"))
2626
#' p + scale_colour_manual(values = cols, breaks = c("8", "6", "4"))
@@ -73,7 +73,6 @@ scale_alpha_manual <- function(..., values) {
7373
manual_scale("alpha", values, ...)
7474
}
7575

76-
7776
manual_scale <- function(aesthetic, values, ...) {
7877
pal <- function(n) {
7978
if (n > length(values)) {

R/scale-shape.r

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
#'
2525
#' # Or for short:
2626
#' d %+% dsmall
27+
#'
28+
#' # Show a list of available shapes
29+
#' df_shapes <- data.frame(shape = 0:24)
30+
#' ggplot(df_shapes, aes(0, 0, shape = shape)) +
31+
#' geom_point(aes(shape = shape), size = 5, fill = 'red') +
32+
#' scale_shape_identity() +
33+
#' facet_wrap(~shape) +
34+
#' theme_void()
2735
scale_shape <- function(..., solid = TRUE) {
2836
discrete_scale("shape", "shape_d", shape_pal(solid), ...)
2937
}

R/stat-.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ Stat <- ggproto("Stat",
6868

6969
compute_layer = function(self, data, params, panels) {
7070
check_required_aesthetics(
71-
self$stat$required_aes,
71+
self$required_aes,
7272
c(names(data), names(params)),
73-
snake_class(self$stat)
73+
snake_class(self)
7474
)
7575

7676
data <- remove_missing(data, params$na.rm,

R/stat-bin.r

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#' example, to center on integers, use \code{width = 1} and \code{boundary =
2121
#' 0.5}, even if \code{1} is outside the range of the data. At most one of
2222
#' \code{center} and \code{boundary} may be specified.
23+
#' @param breaks Alternatively, you can supply a numeric vector giving
24+
#' the bin boundaries. Overrides \code{binwidth}, \code{bins}, \code{center},
25+
#' and \code{boundary}.
2326
#' @param closed One of \code{"right"} or \code{"left"} indicating whether right
2427
#' or left edges of bins are included in the bin.
2528
#' @param pad If \code{TRUE}, adds empty bins at either end of x. This ensures
@@ -44,6 +47,7 @@ stat_bin <- function(mapping = NULL, data = NULL,
4447
bins = NULL,
4548
center = NULL,
4649
boundary = NULL,
50+
breaks = NULL,
4751
closed = c("right", "left"),
4852
pad = FALSE,
4953
na.rm = FALSE,
@@ -63,6 +67,7 @@ stat_bin <- function(mapping = NULL, data = NULL,
6367
bins = bins,
6468
center = center,
6569
boundary = boundary,
70+
breaks = breaks,
6671
closed = closed,
6772
pad = pad,
6873
na.rm = na.rm,

R/stat-contour.r

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ StatContour <- ggproto("StatContour", Stat,
6666
contour_lines <- function(data, breaks, complete = FALSE) {
6767
z <- tapply(data$z, data[c("x", "y")], identity)
6868

69+
if (is.list(z)) {
70+
stop("Contour requires single `z` at each combination of `x` and `y`.",
71+
call. = FALSE)
72+
}
73+
6974
cl <- grDevices::contourLines(
7075
x = sort(unique(data$x)), y = sort(unique(data$y)), z = z,
7176
levels = breaks)

R/stat-ecdf.r

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
#' }
1616
#' @export
1717
#' @examples
18-
#' \donttest{
19-
#' df <- data.frame(x = rnorm(1000))
18+
#' df <- data.frame(
19+
#' x = c(rnorm(100, 0, 3), rnorm(100, 0, 10)),
20+
#' g = gl(2, 100)
21+
#' )
2022
#' ggplot(df, aes(x)) + stat_ecdf(geom = "step")
2123
#'
22-
#' df <- data.frame(x = c(rnorm(100, 0, 3), rnorm(100, 0, 10)),
23-
#' g = gl(2, 100))
24+
#' # Don't go to positive/negative infinity
25+
#' ggplot(df, aes(x)) + stat_ecdf(geom = "step", pad = FALSE)
2426
#'
27+
#' # Multiple ECDFs
2528
#' ggplot(df, aes(x, colour = g)) + stat_ecdf()
26-
#' }
2729
stat_ecdf <- function(mapping = NULL, data = NULL,
2830
geom = "step", position = "identity",
2931
...,
@@ -42,6 +44,7 @@ stat_ecdf <- function(mapping = NULL, data = NULL,
4244
inherit.aes = inherit.aes,
4345
params = list(
4446
n = n,
47+
pad = pad,
4548
na.rm = na.rm,
4649
...
4750
)

R/theme-defaults.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@
4545
#' colour = factor(gear))) + facet_wrap(~am)
4646
#'
4747
#' p
48-
#' p + theme_gray()
4948
#' p + theme_bw()
5049
#' p + theme_linedraw()
5150
#' p + theme_light()
5251
#' p + theme_dark()
5352
#' p + theme_minimal()
5453
#' p + theme_classic()
5554
#' p + theme_void()
55+
#' p + theme_gray() # default theme
5656
#'
5757
#' @name ggtheme
5858
NULL
@@ -137,7 +137,7 @@ theme_grey <- function(base_size = 11, base_family = "") {
137137
plot.caption = element_text(
138138
size = rel(0.9),
139139
hjust = 1,
140-
margin = margin(b = half_line * 0.9)
140+
margin = margin(t = half_line * 0.9)
141141
),
142142
plot.margin = margin(half_line, half_line, half_line, half_line),
143143

R/theme.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ print.theme <- function(x, ...) utils::str(x)
128128
#' legend.key \tab background underneath legend keys
129129
#' (\code{element_rect}; inherits from \code{rect}) \cr
130130
#' legend.key.size \tab size of legend keys
131-
#' (\code{unit}; inherits from \code{legend.key.size}) \cr
131+
#' (\code{unit}) \cr
132132
#' legend.key.height \tab key background height
133133
#' (\code{unit}; inherits from \code{legend.key.size}) \cr
134134
#' legend.key.width \tab key background width

R/utilities-resolution.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Compute the "resolution" of a data vector.
22
#'
3-
#' The resolution is is the smallest non-zero distance between adjacent
3+
#' The resolution is the smallest non-zero distance between adjacent
44
#' values. If there is only one unique value, then the resolution is defined
55
#' to be one.
66
#'

R/utilities.r

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,7 @@ dispatch_args <- function(f, ...) {
280280
formals(f) <- formals
281281
f
282282
}
283+
284+
# Needed to trigger package loading
285+
#' @importFrom tibble tibble
286+
NULL

R/zzz.r

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313
tip <- sample(tips, 1)
1414
packageStartupMessage(paste(strwrap(tip), collapse = "\n"))
1515
}
16+
17+
release_questions <- function() {
18+
c(
19+
"Have you built the book?"
20+
)
21+
}

codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
comment: false

man/annotate.Rd

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fortify.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)