Skip to content

Commit 40bdc73

Browse files
authored
Merge pull request #3 from tidyverse/master
update to tidyverse edition 20191118
2 parents 2fd47b8 + cb0eaa0 commit 40bdc73

Some content is hidden

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

44 files changed

+1114
-170
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ visual_test
2626
^\.github$
2727
^vignettes/profilings
2828
^cran-comments\.md$
29+
^LICENSE\.md$

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Authors@R: c(
1414
person("Claus", "Wilke", role = "aut"),
1515
person("Kara", "Woo", role = "aut"),
1616
person("Hiroaki", "Yutani", role = "aut"),
17+
person("Dewey", "Dunnington", role = "aut"),
1718
person("RStudio", role = c("cph"))
1819
)
1920
Depends:
@@ -23,22 +24,21 @@ Imports:
2324
grDevices,
2425
grid,
2526
gtable (>= 0.1.1),
27+
isoband,
2628
MASS,
2729
mgcv,
2830
reshape2,
2931
rlang (>= 0.3.0),
3032
scales (>= 0.5.0),
3133
stats,
3234
tibble,
33-
viridisLite,
3435
withr (>= 2.0.0)
3536
Suggests:
3637
covr,
3738
dplyr,
3839
ggplot2movies,
3940
hexbin,
4041
Hmisc,
41-
isoband,
4242
knitr,
4343
lattice,
4444
mapproj,

GOVERNANCE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ The core developers of ggplot2 are:
4343
* [Claus Wilke](https://github.com/clauswilke)
4444
* [Kara Woo](https://github.com/karawoo)
4545
* [Hiroaki Yutani](https://github.com/yutannihilation)
46+
* [Dewey Dunnington](https://github.com/paleolimbot)
4647

4748
All core developers are bound by the [code of conduct](CODE_OF_CONDUCT.md).
4849

LICENSE.md

Lines changed: 361 additions & 0 deletions
Large diffs are not rendered by default.

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ S3method(fortify,tbl_df)
4545
S3method(ggplot,"function")
4646
S3method(ggplot,default)
4747
S3method(ggplot_add,"NULL")
48+
S3method(ggplot_add,"function")
4849
S3method(ggplot_add,Coord)
4950
S3method(ggplot_add,Facet)
5051
S3method(ggplot_add,Layer)
@@ -105,6 +106,7 @@ S3method(makeContent,labelgrob)
105106
S3method(makeContext,dotstackGrob)
106107
S3method(merge_element,default)
107108
S3method(merge_element,element)
109+
S3method(merge_element,element_blank)
108110
S3method(plot,ggplot)
109111
S3method(predictdf,default)
110112
S3method(predictdf,glm)
@@ -297,10 +299,12 @@ export(draw_key_timeseries)
297299
export(draw_key_vline)
298300
export(draw_key_vpath)
299301
export(dup_axis)
302+
export(el_def)
300303
export(element_blank)
301304
export(element_grob)
302305
export(element_line)
303306
export(element_rect)
307+
export(element_render)
304308
export(element_text)
305309
export(enexpr)
306310
export(enexprs)

NEWS.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ggplot2 (development version)
22

3+
* `scale_x_continuous()` and `scale_y_continuous()` gains an `n.breaks` argument
4+
guiding the number of automatic generated breaks (@thomasp85, #3102)
5+
6+
* `geom_sf()` now removes rows that can't be plotted due to `NA` aesthetics
7+
(#3546, @thomasp85)
8+
39
* A new scale type has been added, that allows binning of aesthetics at the
410
scale level. It has versions for both position and non-position aesthetics and
511
comes with two new guides (`guide_bins` and `guide_coloursteps`) (@thomasp85, #3096)
@@ -14,6 +20,10 @@
1420
* `Geom` now gains a `setup_params()` method in line with the other ggproto
1521
classes (@thomasp85, #3509)
1622

23+
* Themes can now modify the theme element tree, via the
24+
`element_tree` argument. This allows extension packages to add functionality that
25+
alters the element tree (@clauswilke, #2540).
26+
1727
* `element_text()` now issues a warning when vectorized arguments are provided, as in
1828
`colour = c("red", "green", "blue")`. Such use is discouraged and not officially supported
1929
(@clauswilke, #3492).
@@ -82,12 +92,12 @@
8292

8393
* `stat_density2d()` can now take an `adjust` parameter to scale the default bandwidth. (#2860, @haleyjeppson)
8494

85-
* `geom_sf()` now removes rows that contain missing `shape`/`size`/`colour` (#3483, @yutannihilation)
86-
8795
* Fix a bug when `show.legend` is a named logical vector (#3461, @yutannihilation).
8896

8997
* Increase the default `nbin` of `guide_colourbar()` to place the ticks more precisely (#3508, @yutannihilation).
9098

99+
* `geom_sf()` now applies alpha to linestring geometries (#3589, @yutannihilation).
100+
91101
# ggplot2 3.2.1
92102

93103
This is a patch release fixing a few regressions introduced in 3.2.0 as well as

R/aes-calculated.r

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ is_calculated <- function(x) {
4242
FALSE
4343
} else if (is.symbol(x)) {
4444
is_dotted_var(as.character(x))
45+
} else if (is_quosure(x)) {
46+
is_calculated(quo_get_expr(x))
4547
} else if (is.call(x)) {
4648
if (identical(x[[1]], quote(stat))) {
4749
TRUE
@@ -66,6 +68,12 @@ strip_dots <- function(expr) {
6668
} else {
6769
expr
6870
}
71+
} else if (is_quosure(expr)) {
72+
# strip dots from quosure and reconstruct the quosure
73+
expr <- new_quosure(
74+
strip_dots(quo_get_expr(expr)),
75+
quo_get_env(expr)
76+
)
6977
} else if (is.call(expr)) {
7078
if (identical(expr[[1]], quote(stat))) {
7179
strip_dots(expr[[2]])

R/bin.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ bin_breaks_width <- function(x_range, width = NULL, center = NULL,
8787
max_x <- x_range[2] + (1 - 1e-08) * width
8888
breaks <- seq(origin, max_x, width)
8989

90-
if (length(breaks) > 1e6) {
90+
if (length(breaks) == 1) {
91+
# In exceptionally rare cases, the above can fail and produce only a
92+
# single break (see issue #3606). We fix this by adding a second break.
93+
breaks <- c(breaks, breaks + width)
94+
} else if (length(breaks) > 1e6) {
9195
stop("The number of histogram bins must be less than 1,000,000.\nDid you make `binwidth` too small?", call. = FALSE)
9296
}
9397

R/geom-dotplot.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#' @inheritParams geom_point
3535
#' @param stackdir which direction to stack the dots. "up" (default),
3636
#' "down", "center", "centerwhole" (centered, but with dots aligned)
37-
#' @param stackratio how close to stack the dots. Default is 1, where dots just
37+
#' @param stackratio how close to stack the dots. Default is 1, where dots
3838
#' just touch. Use smaller values for closer, overlapping dots.
3939
#' @param dotsize The diameter of the dots relative to `binwidth`, default 1.
4040
#' @param stackgroups should dots be stacked across groups? This has the effect

R/geom-ribbon.r

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
#' h + geom_ribbon(aes(ymin=0, ymax=level))
3131
#' h + geom_area(aes(y = level))
3232
#'
33-
#' # Change orientation be switching the mapping
34-
#' h + geom_area(aes(x = level, y = year))
33+
#' # Orientation cannot be deduced by mapping, so must be given explicitly for
34+
#' # flipped orientation
35+
#' h + geom_area(aes(x = level, y = year), orientation = "y")
3536
#'
3637
#' # Add aesthetic mappings
3738
#' h +

R/geom-sf.R

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,27 @@ NULL
8686
#' @usage NULL
8787
#' @format NULL
8888
GeomSf <- ggproto("GeomSf", Geom,
89-
required_aes = "geometry",
90-
default_aes = aes(
91-
shape = NULL,
92-
colour = NULL,
93-
fill = NULL,
94-
size = NULL,
95-
linetype = 1,
96-
alpha = NA,
97-
stroke = 0.5
98-
),
89+
required_aes = "geometry",
90+
default_aes = aes(
91+
shape = NULL,
92+
colour = NULL,
93+
fill = NULL,
94+
size = NULL,
95+
linetype = 1,
96+
alpha = NA,
97+
stroke = 0.5
98+
),
9999

100-
non_missing_aes = c("size", "shape", "colour"),
101-
102100
draw_panel = function(data, panel_params, coord, legend = NULL,
103-
lineend = "butt", linejoin = "round", linemitre = 10) {
101+
lineend = "butt", linejoin = "round", linemitre = 10,
102+
na.rm = TRUE) {
104103
if (!inherits(coord, "CoordSf")) {
105104
stop("geom_sf() must be used with coord_sf()", call. = FALSE)
106105
}
107106

108107
# Need to refactor this to generate one grob per geometry type
109108
coord <- coord$transform(data, panel_params)
110-
sf_grob(coord, lineend = lineend, linejoin = linejoin, linemitre = linemitre)
109+
sf_grob(coord, lineend = lineend, linejoin = linejoin, linemitre = linemitre, na.rm = na.rm)
111110
},
112111

113112
draw_key = function(data, params, size) {
@@ -132,37 +131,57 @@ default_aesthetics <- function(type) {
132131
}
133132
}
134133

135-
sf_grob <- function(x, lineend = "butt", linejoin = "round", linemitre = 10) {
136-
# Need to extract geometry out of corresponding list column
137-
geometry <- x$geometry
138-
type <- sf_types[sf::st_geometry_type(geometry)]
139-
is_point <- type %in% "point"
140-
type_ind <- match(type, c("point", "line", "other"))
134+
sf_grob <- function(x, lineend = "butt", linejoin = "round", linemitre = 10, na.rm = TRUE) {
135+
type <- sf_types[sf::st_geometry_type(x$geometry)]
136+
is_point <- type == "point"
137+
is_line <- type == "line"
138+
is_other <- type == "other"
139+
is_collection <- type == "collection"
140+
type_ind <- match(type, c("point", "line", "other", "collection"))
141+
remove <- rep_len(FALSE, nrow(x))
142+
remove[is_point] <- detect_missing(x, c(GeomPoint$required_aes, GeomPoint$non_missing_aes))[is_point]
143+
remove[is_line] <- detect_missing(x, c(GeomPath$required_aes, GeomPath$non_missing_aes))[is_line]
144+
remove[is_other] <- detect_missing(x, c(GeomPolygon$required_aes, GeomPolygon$non_missing_aes))[is_other]
145+
if (any(remove)) {
146+
if (!na.rm) {
147+
warning_wrap(
148+
"Removed ", sum(remove), " rows containing missing values (geom_sf)."
149+
)
150+
}
151+
x <- x[!remove, , drop = FALSE]
152+
type_ind <- type_ind[!remove]
153+
is_collection <- is_collection[!remove]
154+
}
141155
defaults <- list(
142156
GeomPoint$default_aes,
143157
GeomLine$default_aes,
144158
modify_list(GeomPolygon$default_aes, list(fill = "grey90", colour = "grey35"))
145159
)
160+
defaults[[4]] <- modify_list(
161+
defaults[[3]],
162+
rename(GeomPoint$default_aes, c(size = "point_size", fill = "point_fill"))
163+
)
146164
default_names <- unique(unlist(lapply(defaults, names)))
147165
defaults <- lapply(setNames(default_names, default_names), function(n) {
148166
unlist(lapply(defaults, function(def) def[[n]] %||% NA))
149167
})
150168
alpha <- x$alpha %||% defaults$alpha[type_ind]
151169
col <- x$colour %||% defaults$colour[type_ind]
152-
col[is_point] <- alpha(col[is_point], alpha[is_point])
170+
col[is_point | is_line] <- alpha(col[is_point | is_line], alpha[is_point | is_line])
153171
fill <- x$fill %||% defaults$fill[type_ind]
154172
fill <- alpha(fill, alpha)
155173
size <- x$size %||% defaults$size[type_ind]
174+
point_size <- ifelse(is_collection, x$size %||% defaults$point_size[type_ind], size)
156175
stroke <- (x$stroke %||% defaults$stroke[1]) * .stroke / 2
157-
fontsize <- size * .pt + stroke
176+
fontsize <- point_size * .pt + stroke
158177
lwd <- ifelse(is_point, stroke, size * .pt)
159178
pch <- x$shape %||% defaults$shape[type_ind]
160179
lty <- x$linetype %||% defaults$linetype[type_ind]
161180
gp <- gpar(
162181
col = col, fill = fill, fontsize = fontsize, lwd = lwd, lty = lty,
163182
lineend = lineend, linejoin = linejoin, linemitre = linemitre
164183
)
165-
sf::st_as_grob(geometry, pch = pch, gp = gp)
184+
sf::st_as_grob(x$geometry, pch = pch, gp = gp)
166185
}
167186

168187
#' @export
@@ -280,7 +299,7 @@ geom_sf_text <- function(mapping = aes(), data = NULL,
280299

281300
sf_types <- c(GEOMETRY = "other", POINT = "point", LINESTRING = "line",
282301
POLYGON = "other", MULTIPOINT = "point", MULTILINESTRING = "line",
283-
MULTIPOLYGON = "other", GEOMETRYCOLLECTION = "other",
302+
MULTIPOLYGON = "other", GEOMETRYCOLLECTION = "collection",
284303
CIRCULARSTRING = "line", COMPOUNDCURVE = "other", CURVEPOLYGON = "other",
285304
MULTICURVE = "other", MULTISURFACE = "other", CURVE = "other",
286305
SURFACE = "other", POLYHEDRALSURFACE = "other", TIN = "other",

R/guide-bins.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,14 @@ guide_gengrob.bins <- function(guide, theme) {
320320

321321
key_size_mat <- do.call("cbind",
322322
lapply(guide$geoms, function(g) g$data$size / 10)
323-
)[seq_len(n_keys), , drop = FALSE]
323+
)
324324

325+
# key_size_mat can be an empty matrix (e.g. the data doesn't contain size
326+
# column), so subset it only when it has any rows and columns.
325327
if (nrow(key_size_mat) == 0 || ncol(key_size_mat) == 0) {
326328
key_size_mat <- matrix(0, ncol = 1, nrow = n_keys)
329+
} else {
330+
key_size_mat <- key_size_mat[seq_len(n_keys), , drop = FALSE]
327331
}
328332
key_sizes <- apply(key_size_mat, 1, max)
329333

R/guide-legend.r

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ guide_train.legend <- function(guide, scale, aesthetic = NULL) {
230230

231231
#' @export
232232
guide_merge.legend <- function(guide, new_guide) {
233-
guide$key <- merge(guide$key, new_guide$key, sort = FALSE)
233+
new_guide$key$.label <- NULL
234+
guide$key <- cbind(guide$key, new_guide$key)
234235
guide$override.aes <- c(guide$override.aes, new_guide$override.aes)
235236
if (any(duplicated(names(guide$override.aes)))) {
236237
warning("Duplicated override.aes is ignored.")

R/guides-axis.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ guide_train.axis <- function(guide, scale, aesthetic = NULL) {
9393
}
9494
}
9595

96-
guide$key <- ticks
96+
guide$key <- ticks[is.finite(ticks[[aesthetic]]), ]
9797
}
9898

9999
guide$name <- paste0(guide$name, "_", aesthetic)

R/plot-construction.r

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ggplot_add <- function(object, plot, object_name) {
8888
}
8989
#' @export
9090
ggplot_add.default <- function(object, plot, object_name) {
91-
stop("Don't know how to add ", object_name, " to a plot", call. = FALSE)
91+
stop("Can't add `", object_name, "` to a ggplot object.", call. = FALSE)
9292
}
9393
#' @export
9494
ggplot_add.NULL <- function(object, plot, object_name) {
@@ -100,6 +100,14 @@ ggplot_add.data.frame <- function(object, plot, object_name) {
100100
plot
101101
}
102102
#' @export
103+
ggplot_add.function <- function(object, plot, object_name) {
104+
stop(
105+
"Can't add `", object_name, "` to a ggplot object.\n",
106+
"Did you forget to add parentheses, as in `",
107+
object_name, "()`?", call. = FALSE
108+
)
109+
}
110+
#' @export
103111
ggplot_add.theme <- function(object, plot, object_name) {
104112
plot$theme <- add_theme(plot$theme, object)
105113
plot

0 commit comments

Comments
 (0)