Skip to content

Commit 00e4a1d

Browse files
author
koneill
committed
Merge remote branch 'upstream/master'
2 parents e66a90d + 0cd0bac commit 00e4a1d

File tree

131 files changed

+1710
-1101
lines changed

Some content is hidden

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

131 files changed

+1710
-1101
lines changed

.Rbuildignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ visual_test
99
^data-raw$
1010
^CONTRIBUTING\.md$
1111
^NEWS$
12-
^NEWS\.md$
1312
^revdep$

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ Suggests:
3636
nlme,
3737
testthat,
3838
quantreg,
39-
knitr
39+
knitr,
40+
svglite
4041
Enhances: sp
4142
License: GPL-2
4243
URL: http://ggplot2.org, https://github.com/hadley/ggplot2
@@ -169,6 +170,7 @@ Collate:
169170
'scale-manual.r'
170171
'scale-shape.r'
171172
'scale-size.r'
173+
'scale-type.R'
172174
'scales-.r'
173175
'stat-bin.r'
174176
'stat-bin2d.r'

NAMESPACE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ S3method(format,facet)
3636
S3method(format,ggproto)
3737
S3method(format,ggproto_method)
3838
S3method(fortify,"NULL")
39+
S3method(fortify,"function")
3940
S3method(fortify,Line)
4041
S3method(fortify,Lines)
4142
S3method(fortify,Polygon)
@@ -103,6 +104,7 @@ S3method(scale_type,default)
103104
S3method(scale_type,factor)
104105
S3method(scale_type,logical)
105106
S3method(scale_type,numeric)
107+
S3method(scale_type,ordered)
106108
S3method(str,uneval)
107109
S3method(summary,ggplot)
108110
S3method(widthDetails,stripGrob)
@@ -372,6 +374,8 @@ export(scale_color_identity)
372374
export(scale_color_manual)
373375
export(scale_colour_brewer)
374376
export(scale_colour_continuous)
377+
export(scale_colour_date)
378+
export(scale_colour_datetime)
375379
export(scale_colour_discrete)
376380
export(scale_colour_distiller)
377381
export(scale_colour_gradient)
@@ -383,6 +387,8 @@ export(scale_colour_identity)
383387
export(scale_colour_manual)
384388
export(scale_fill_brewer)
385389
export(scale_fill_continuous)
390+
export(scale_fill_date)
391+
export(scale_fill_datetime)
386392
export(scale_fill_discrete)
387393
export(scale_fill_distiller)
388394
export(scale_fill_gradient)
@@ -406,6 +412,8 @@ export(scale_shape_manual)
406412
export(scale_size)
407413
export(scale_size_area)
408414
export(scale_size_continuous)
415+
export(scale_size_date)
416+
export(scale_size_datetime)
409417
export(scale_size_discrete)
410418
export(scale_size_identity)
411419
export(scale_size_manual)

NEWS.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,78 @@
11
# ggplot2 2.0.0.9000
22

3+
* `layer()` now accepts a function as the data argument. The function will be
4+
applied to the data passed to the `ggplot()` function and must return a
5+
data.frame (#1527).
6+
7+
* The theme can now modify the margins of legend title and text (#1502).
8+
9+
* `scale_size()` warns when used with categorical data.
10+
11+
* `scale_size()`, `scale_colour()`, and `scale_fill()` gain date and date-time
12+
variants (#1526).
13+
14+
* `stat_function()` gains an `xlim` parameter (#1528).
15+
16+
* `stat_summary()` preserves sorted x order which avoids artefacts when
17+
display results with `geom_smooth()` (#1520).
18+
19+
* All `geom_()` and `stat_()` function now have consistent argument order:
20+
data + mapping, geom/stat/position, ..., specific arguments, common arguments
21+
to all layers (#1305). This may break code if you were previously relying on
22+
partial name matching, but in the long-term should make ggplot2 easier to
23+
use.
24+
25+
* `stat_ecdf()` does a better job of adding padding to -Inf/Inf, and gains
26+
an argument `pad` to suppress the padding if not needed (#1467).
27+
28+
* `theme_void()` was completely void of text but facets and legends still
29+
needed labels. They are now visible (@jiho).
30+
31+
* Multipanel empty data is correctly plotted, rather than throwing an unhelpful
32+
error (#1445).
33+
34+
* Eliminate spurious warning if you have a layer with no data and no aesthetics
35+
(#1451).
36+
37+
* `position = "nudge"` now works (although it doesn't do anything useful)
38+
(#1428).
39+
40+
* You can once again set legend key and height width to unit arithmetic
41+
objects (like `2 * unit(1, "cm")`) (#1437).
42+
43+
* When mapping an aesthetic to a constant (e.g.
44+
`geom_smooth(aes(colour = "loess")))`), the default guide title is the name
45+
of the aesthetic, not the value (#1431).
46+
47+
* `ggsave("x.svg")` now uses svglite to produce the svg (#1432).
48+
49+
* `stat_bin()` has been overhauled to use the same algorithm as ggvis, which
50+
has been considerably improved thanks to the advice of Randy Prium (@rpruim).
51+
This includes:
52+
53+
* Better arguments and a better algorithm for determining the origin.
54+
You can now specify either `boundary` or the `center` of a bin.
55+
`origin` has been deprecated in favour of these arguments.
56+
57+
* `drop` is deprecated in favour of `pad`, which adds extra 0-count bins
58+
at either end. This is needed for frequency polygons. `geom_histogram()`
59+
defaults to `pad = FALSE` which considerably improves the default limits
60+
for the histogram, especially when the bins are big (#1477).
61+
62+
* The default algorithm does a better job at picking nice width and
63+
origins across a wider range of input data.
64+
65+
This change brings with the removal of some rarely used features:
66+
67+
* The `breaks` argument is no longer supported - this was rarely used
68+
and didn't work correctly for frequency polygons.
69+
70+
* `geom_tile()` uses `draw_key_polygon()` for better legend keys, including
71+
coloured outline (#1484).
72+
73+
* The position of `...` in `geom_density2d()` has been adjusted so you can
74+
set the `n` parameter (#1485).
75+
376
* The default scale for columns of class "AsIs" is now "identity" (#1518).
477

578
* `geom_boxplot()` now understands `outlier.color` (#1455).

R/aes.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ is_position_aes <- function(vars) {
112112
#' evaluation to capture the variable names. \code{aes_} and \code{aes_string}
113113
#' require you to explicitly quote the inputs either with \code{""} for
114114
#' \code{aes_string()}, or with \code{quote} or \code{~} for \code{aes_()}.
115-
#' (\code{aes_q} is an alias to \code{aeq_})
115+
#' (\code{aes_q} is an alias to \code{aes_})
116116
#'
117117
#' It's better to use \code{aes_q()}, because there's no easy way to create the
118118
#' equivalent to \code{aes(colour = "my colour")} or \code{aes{x = `X$1`}}

R/facet-grid-.r

Lines changed: 38 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -45,119 +45,69 @@
4545
#' will be shown, regardless of whether or not they appear in the data.
4646
#' @export
4747
#' @examples
48-
#' \donttest{
49-
#' p <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
50-
#' # With one variable
51-
#' p + facet_grid(. ~ cyl)
52-
#' p + facet_grid(cyl ~ .)
48+
#' p <- ggplot(mpg, aes(displ, cty)) + geom_point()
5349
#'
54-
#' # With two variables
55-
#' p + facet_grid(vs ~ am)
56-
#' p + facet_grid(am ~ vs)
57-
#' p + facet_grid(vs ~ am, margins=TRUE)
50+
#' p + facet_grid(. ~ cyl)
51+
#' p + facet_grid(drv ~ .)
52+
#' p + facet_grid(drv ~ cyl)
5853
#'
5954
#' # To change plot order of facet grid,
6055
#' # change the order of variable levels with factor()
6156
#'
62-
#' set.seed(6809)
63-
#' diamonds <- diamonds[sample(nrow(diamonds), 1000), ]
64-
#' diamonds$cut <- factor(diamonds$cut,
65-
#' levels = c("Ideal", "Very Good", "Fair", "Good", "Premium"))
66-
#'
67-
#' # Repeat first example with new order
68-
#' p <- ggplot(diamonds, aes(carat, ..density..)) +
69-
#' geom_histogram(binwidth = 1)
70-
#' p + facet_grid(. ~ cut)
71-
#'
72-
#' g <- ggplot(mtcars, aes(mpg, wt)) +
73-
#' geom_point()
74-
#' g + facet_grid(. ~ vs + am)
75-
#' g + facet_grid(vs + am ~ .)
76-
#'
77-
#' # You can also use strings, which makes it a little easier
78-
#' # when writing functions that generate faceting specifications
79-
#'
80-
#' p + facet_grid("cut ~ .")
81-
#'
82-
#' # see also ?plotmatrix for the scatterplot matrix
83-
#'
84-
#' # If there isn't any data for a given combination, that panel
85-
#' # will be empty
86-
#'
87-
#' g + facet_grid(cyl ~ vs)
88-
#'
8957
#' # If you combine a facetted dataset with a dataset that lacks those
9058
#' # facetting variables, the data will be repeated across the missing
9159
#' # combinations:
92-
#'
93-
#' g + facet_grid(vs ~ cyl)
94-
#'
95-
#' df <- data.frame(mpg = 22, wt = 3)
96-
#' g + facet_grid(vs ~ cyl) +
60+
#' df <- data.frame(displ = mean(mpg$displ), cty = mean(mpg$cty))
61+
#' p +
62+
#' facet_grid(. ~ cyl) +
9763
#' geom_point(data = df, colour = "red", size = 2)
9864
#'
99-
#' df2 <- data.frame(mpg = c(19, 22), wt = c(2,4), vs = c(0, 1))
100-
#' g + facet_grid(vs ~ cyl) +
101-
#' geom_point(data = df2, colour = "red", size = 2)
102-
#'
103-
#' df3 <- data.frame(mpg = c(19, 22), wt = c(2,4), vs = c(1, 1))
104-
#' g + facet_grid(vs ~ cyl) +
105-
#' geom_point(data = df3, colour = "red", size = 2)
106-
#'
107-
#'
65+
#' # Free scales -------------------------------------------------------
10866
#' # You can also choose whether the scales should be constant
10967
#' # across all panels (the default), or whether they should be allowed
11068
#' # to vary
11169
#' mt <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) +
11270
#' geom_point()
11371
#'
11472
#' mt + facet_grid(. ~ cyl, scales = "free")
73+
#'
11574
#' # If scales and space are free, then the mapping between position
116-
#' # and values in the data will be the same across all panels
117-
#' mt + facet_grid(. ~ cyl, scales = "free", space = "free")
75+
#' # and values in the data will be the same across all panels. This
76+
#' # is particularly useful for categorical axes
77+
#' ggplot(mpg, aes(drv, model)) +
78+
#' geom_point() +
79+
#' facet_grid(manufacturer ~ ., scales = "free", space = "free") +
80+
#' theme(strip.text.y = element_text(angle = 0))
11881
#'
119-
#' mt + facet_grid(vs ~ am, scales = "free")
120-
#' mt + facet_grid(vs ~ am, scales = "free_x")
121-
#' mt + facet_grid(vs ~ am, scales = "free_y")
122-
#' mt + facet_grid(vs ~ am, scales = "free", space = "free")
123-
#' mt + facet_grid(vs ~ am, scales = "free", space = "free_x")
124-
#' mt + facet_grid(vs ~ am, scales = "free", space = "free_y")
82+
#' # Facet labels ------------------------------------------------------
83+
#' p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
84+
#' p
12585
#'
126-
#' # You may need to set your own breaks for consistent display:
127-
#' mt + facet_grid(. ~ cyl, scales = "free_x", space = "free") +
128-
#' scale_x_continuous(breaks = seq(10, 36, by = 2))
129-
#' # Adding scale limits override free scales:
130-
#' last_plot() + xlim(10, 15)
86+
#' # label_both() displays both variable name and value
87+
#' p + facet_grid(vs ~ cyl, labeller = label_both)
13188
#'
132-
#' # Free scales are particularly useful for categorical variables
133-
#' ggplot(mpg, aes(cty, model)) +
89+
#' # label_parsed() parses text into mathematical expressions, see ?plotmath
90+
#' mtcars$cyl2 <- factor(mtcars$cyl, labels = c("alpha", "beta", "sqrt(x, y)"))
91+
#' ggplot(mtcars, aes(wt, mpg)) +
13492
#' geom_point() +
135-
#' facet_grid(manufacturer ~ ., scales = "free", space = "free")
136-
#' # particularly when you reorder factor levels
137-
#' mpg$model <- reorder(mpg$model, mpg$cty)
138-
#' manufacturer <- reorder(mpg$manufacturer, mpg$cty)
139-
#' last_plot() %+% mpg + theme(strip.text.y = element_text())
93+
#' facet_grid(. ~ cyl2, labeller = label_parsed)
14094
#'
141-
#' # Use as.table to to control direction of horizontal facets, TRUE by default
142-
#' h <- ggplot(mtcars, aes(x = mpg, y = wt)) +
143-
#' geom_point()
144-
#' h + facet_grid(cyl ~ vs)
145-
#' h + facet_grid(cyl ~ vs, as.table = FALSE)
95+
#' # label_bquote() makes it easy to construct math expressions
96+
#' p + facet_grid(. ~ vs, labeller = label_bquote(cols = alpha ^ .(vs)))
14697
#'
147-
#' # Use labeller to control facet labels, label_value is default
148-
#' h + facet_grid(cyl ~ vs, labeller = label_both)
149-
#' # Using label_parsed, see ?plotmath for more options
150-
#' mtcars$cyl2 <- factor(mtcars$cyl, labels = c("alpha", "beta", "sqrt(x, y)"))
151-
#' k <- ggplot(mtcars, aes(wt, mpg)) +
152-
#' geom_point()
153-
#' k + facet_grid(. ~ cyl2)
154-
#' k + facet_grid(. ~ cyl2, labeller = label_parsed)
155-
#' # For label_bquote the label value is x.
156-
#' p <- ggplot(mtcars, aes(wt, mpg)) +
157-
#' geom_point()
158-
#' p + facet_grid(. ~ vs, labeller = label_bquote(alpha ^ .(x)))
159-
#' p + facet_grid(. ~ vs, labeller = label_bquote(.(x) ^ .(x)))
98+
#' # The facet strips can be displayed near the axes with switch
99+
#' data <- transform(mtcars,
100+
#' am = factor(am, levels = 0:1, c("Automatic", "Manual")),
101+
#' gear = factor(gear, levels = 3:5, labels = c("Three", "Four", "Five"))
102+
#' )
103+
#' p <- ggplot(data, aes(mpg, disp)) + geom_point()
104+
#' p + facet_grid(am ~ gear, switch = "both")
105+
#' # It looks better without boxes around the strips
106+
#' p + facet_grid(am ~ gear, switch = "both") +
107+
#' theme(strip.background = element_blank())
160108
#'
109+
#' # Margins ----------------------------------------------------------
110+
#' \dontrun{
161111
#' # Margins can be specified by logically (all yes or all no) or by specific
162112
#' # variables as (character) variable names
163113
#' mg <- ggplot(mtcars, aes(x = mpg, y = wt)) + geom_point()
@@ -170,20 +120,6 @@
170120
#' mg + facet_grid(vs + am ~ gear, margins = "vs")
171121
#' mg + facet_grid(vs + am ~ gear, margins = "gear")
172122
#' mg + facet_grid(vs + am ~ gear, margins = c("gear", "am"))
173-
#'
174-
#' # The facet strips can be displayed near the axes with switch
175-
#' data <- transform(mtcars,
176-
#' am = factor(am, levels = 0:1, c("Automatic", "Manual")),
177-
#' gear = factor(gear, levels = 3:5, labels = c("Three", "Four", "Five"))
178-
#' )
179-
#' p <- ggplot(data, aes(mpg, disp)) + geom_point()
180-
#' p + facet_grid(am ~ gear, switch = "both") + theme_light()
181-
#'
182-
#' # It may be more aesthetic to use a theme without boxes around
183-
#' # around the strips.
184-
#' p + facet_grid(am ~ gear + vs, switch = "y") + theme_minimal()
185-
#' p + facet_grid(am ~ ., switch = "y") +
186-
#' theme_gray() %+replace% theme(strip.background = element_blank())
187123
#' }
188124
#' @importFrom plyr as.quoted
189125
facet_grid <- function(facets, margins = FALSE, scales = "fixed", space = "fixed", shrink = TRUE, labeller = "label_value", as.table = TRUE, switch = NULL, drop = TRUE) {

R/fortify.r

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ fortify.data.frame <- function(model, data, ...) model
1616
#' @export
1717
fortify.NULL <- function(model, data, ...) waiver()
1818
#' @export
19+
fortify.function <- function(model, data, ...) model
20+
#' @export
1921
fortify.default <- function(model, data, ...) {
2022
stop(
2123
"ggplot2 doesn't know how to deal with data of class ",

R/geom-.r

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ Geom <- ggproto("Geom",
6767
},
6868

6969
draw_layer = function(self, data, params, panel, coord) {
70-
if (empty(data)) return(list(zeroGrob()))
70+
if (empty(data)) {
71+
n <- if (is.factor(data$PANEL)) nlevels(data$PANEL) else 1L
72+
return(rep(list(zeroGrob()), n))
73+
}
7174

7275
# Trim off extra parameters
7376
params <- params[intersect(names(params), self$parameters())]

R/geom-abline.r

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ NULL
6969
#' facet_wrap(~ cyl)
7070
geom_abline <- function(mapping = NULL, data = NULL,
7171
...,
72-
slope, intercept,
73-
na.rm = FALSE, show.legend = NA) {
72+
slope,
73+
intercept,
74+
na.rm = FALSE,
75+
show.legend = NA) {
7476

7577
# If nothing set, default to y = x
7678
if (missing(mapping) && missing(slope) && missing(intercept)) {

R/geom-bar.r

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,14 @@
7373
#' }
7474
#' ggplot(mpg, aes(reorder_size(class))) + geom_bar()
7575
#' }
76-
geom_bar <- function(mapping = NULL, data = NULL, stat = "count",
77-
position = "stack", width = NULL, binwidth = NULL, ...,
78-
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) {
76+
geom_bar <- function(mapping = NULL, data = NULL,
77+
stat = "count", position = "stack",
78+
...,
79+
width = NULL,
80+
binwidth = NULL,
81+
na.rm = FALSE,
82+
show.legend = NA,
83+
inherit.aes = TRUE) {
7984

8085
if (!is.null(binwidth)) {
8186
warning("`geom_bar()` no longer has a `binwidth` parameter. ",

0 commit comments

Comments
 (0)