Skip to content

Commit

Permalink
Merge branch 'master' into v3.2.1-rc
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Aug 12, 2019
2 parents ee20fe8 + 541ae99 commit 8f27d7a
Show file tree
Hide file tree
Showing 136 changed files with 5,402 additions and 1,870 deletions.
17 changes: 10 additions & 7 deletions .travis.yml
@@ -1,7 +1,5 @@
language: R
cache: packages
sudo: true
dist: trusty

# build matrix; turn on vdiffr only on r release
matrix:
Expand Down Expand Up @@ -35,8 +33,13 @@ env:
after_success:
- Rscript -e 'covr::codecov()'

before_install:
- sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable --yes
- sudo apt-get --yes --force-yes update -qq
- sudo apt-get install --yes libudunits2-dev libproj-dev libgeos-dev libgdal-dev
- Rscript -e 'update.packages(ask = FALSE)'
addons:
apt:
sources:
- sourceline: 'ppa:ubuntugis/ppa'
packages:
- libudunits2-dev
- libproj-dev
- libgeos-dev
- libgdal-dev

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -6,7 +6,7 @@ quickly as possible. The guide is divided into two main pieces:
1. Filing a bug report or feature request in an issue.
1. Suggesting a change via a pull request.

Please note that ggplot2 is released with a [Contributor Code of Conduct](.github/CODE_OF_CONDUCT.md). By contributing to this project,
Please note that ggplot2 is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By contributing to this project,
you agree to abide by its terms.

## Issues
Expand Down
5 changes: 4 additions & 1 deletion DESCRIPTION
Expand Up @@ -39,6 +39,7 @@ Suggests:
ggplot2movies,
hexbin,
Hmisc,
isoband,
knitr,
lattice,
mapproj,
Expand All @@ -54,7 +55,7 @@ Suggests:
rpart,
sf (>= 0.7-3),
svglite (>= 1.2.0.9001),
testthat (>= 0.11.0),
testthat (>= 2.1.0),
vdiffr (>= 0.3.0)
Enhances: sp
License: GPL-2 | file LICENSE
Expand Down Expand Up @@ -190,6 +191,7 @@ Collate:
'scale-continuous.r'
'scale-date.r'
'scale-discrete-.r'
'scale-expansion.r'
'scale-gradient.r'
'scale-grey.r'
'scale-hue.r'
Expand All @@ -199,6 +201,7 @@ Collate:
'scale-shape.r'
'scale-size.r'
'scale-type.R'
'scale-view.r'
'scale-viridis.r'
'scales-.r'
'stat-bin.r'
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Expand Up @@ -49,6 +49,7 @@ S3method(ggplot_add,Coord)
S3method(ggplot_add,Facet)
S3method(ggplot_add,Layer)
S3method(ggplot_add,Scale)
S3method(ggplot_add,by)
S3method(ggplot_add,data.frame)
S3method(ggplot_add,default)
S3method(ggplot_add,guides)
Expand Down Expand Up @@ -204,6 +205,7 @@ export(StatBindot)
export(StatBinhex)
export(StatBoxplot)
export(StatContour)
export(StatContourFilled)
export(StatCount)
export(StatDensity)
export(StatDensity2d)
Expand Down Expand Up @@ -290,6 +292,7 @@ export(ensym)
export(ensyms)
export(expand_limits)
export(expand_scale)
export(expansion)
export(expr)
export(facet_grid)
export(facet_null)
Expand All @@ -304,6 +307,7 @@ export(geom_blank)
export(geom_boxplot)
export(geom_col)
export(geom_contour)
export(geom_contour_filled)
export(geom_count)
export(geom_crossbar)
export(geom_curve)
Expand Down Expand Up @@ -518,6 +522,7 @@ export(stat_bin_hex)
export(stat_binhex)
export(stat_boxplot)
export(stat_contour)
export(stat_contour_filled)
export(stat_count)
export(stat_density)
export(stat_density2d)
Expand Down
55 changes: 55 additions & 0 deletions NEWS.md
@@ -1,5 +1,60 @@
# ggplot2 (development version)

* stacking text when calculating the labels and the y axis with
`stat_summary()` now works (@ikosmidis, #2709)

* Allowed reversing of discrete scales by re-writing `get_limits()` (@AnneLyng, #3115)

* Added `stat_contour_filled()` and `geom_contour_filled()`, which compute
and draw filled contours of gridded data (@paleolimbot, #3044).

* `geom_contour()` and `stat_contour()` now use the isoband package
to compute contour lines. The `complete` parameter (which was undocumented
and has been unused for at least four years) was removed (@paleolimbot, #3044).

* `stat_smooth()` user `REML` by default, if `method = "gam"` and
`gam`'s method is not specified (@ikosmidis, #2630).

* Changed `theme_grey()` setting for legend key so that it creates no
border (`NA`) rather than drawing a white one. (@annennenne, #3180)

* Added function `ggplot_add.by()` for lists created with `by()` (#2734, @Maschette)

* `ggdep()` was deprecated (@perezp44, #3382).

* Added weight aesthetic option to `stat_density()` and made scaling of
weights the default (@annennenne, #2902)

* `expand_scale()` was deprecated in favour of `expansion()` for setting
the `expand` argument of `x` and `y` scales (@paleolimbot).

* `coord_trans()` now draws second axes and accepts `xlim`, `ylim`,
and `expand` arguments to bring it up to feature parity with
`coord_cartesian()`. The `xtrans` and `ytrans` arguments that were
deprecated in version 1.0.1 in favour of `x` and `y`
were removed (@paleolimbot, #2990).

* `coord_trans()` now calculates breaks using the expanded range
(previously these were calculated using the unexpanded range,
which resulted in differences between plots made with `coord_trans()`
and those made with `coord_cartesian()`). The expansion for discrete axes
in `coord_trans()` was also updated such that it behaves identically
to that in `coord_cartesian()` (@paleolimbot, #3338).

* All `coord_*()` functions with `xlim` and `ylim` arguments now accept
vectors with `NA` as a placeholder for the minimum or maximum value
(e.g., `ylim = c(0, NA)` would zoom the y-axis from 0 to the
maximum value observed in the data). This mimics the behaviour
of the `limits` argument in continuous scale functions
(@paleolimbot, #2907).

* `geom_abline()`, `geom_hline()`, and `geom_vline()` now issue
more informative warnings when supplied with set aesthetics
(i.e., `slope`, `intercept`, `yintercept`, and/or `xintercept`)
and mapped aesthetics (i.e., `data` and/or `mapping`).

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

# ggplot2 3.2.1

This is a patch release fixing a few regressions introduced in 3.2.0 as well as
Expand Down
66 changes: 61 additions & 5 deletions R/aes.r
Expand Up @@ -8,8 +8,8 @@ NULL
#' [ggplot2()] and in individual layers.
#'
#' This function also standardises aesthetic names by converting `color` to `colour`
#' (also in substrings, e.g. `point_color` to `point_colour`) and translating old style
#' R names to ggplot names (eg. `pch` to `shape`, `cex` to `size`).
#' (also in substrings, e.g., `point_color` to `point_colour`) and translating old style
#' R names to ggplot names (e.g., `pch` to `shape` and `cex` to `size`).
#'
#' @section Quasiquotation:
#'
Expand All @@ -22,9 +22,13 @@ NULL
#' programming vignette](http://dplyr.tidyverse.org/articles/programming.html)
#' to learn more about these techniques.
#'
#' @param x,y,... List of name value pairs giving aesthetics to map to
#' variables. The names for x and y aesthetics are typically omitted because
#' they are so common; all other aesthetics must be named.
#' @param x,y,... List of name-value pairs in the form `aesthetic = variable`
#' describing which variables in the layer data should be mapped to which
#' aesthetics used by the paired geom/stat. The expression `variable` is
#' evaluated within the layer data, so there is no need to refer to
#' the original dataset (i.e., use `ggplot(df, aes(variable))`
#' instead of `ggplot(df, aes(df$variable))`). The names for x and y aesthetics
#' are typically omitted because they are so common; all other aesthetics must be named.
#' @seealso [vars()] for another quoting function designed for
#' faceting specifications.
#' @return A list with class `uneval`. Components of the list are either
Expand Down Expand Up @@ -334,3 +338,55 @@ mapped_aesthetics <- function(x) {
is_null <- vapply(x, is.null, logical(1))
names(x)[!is_null]
}


#' Check a mapping for discouraged usage
#'
#' Checks that `$` and `[[` are not used when the target *is* the data
#'
#' @param mapping A mapping created with [aes()]
#' @param data The data to be mapped from
#'
#' @noRd
warn_for_aes_extract_usage <- function(mapping, data) {
lapply(mapping, function(quosure) {
warn_for_aes_extract_usage_expr(get_expr(quosure), data, get_env(quosure))
})
}

warn_for_aes_extract_usage_expr <- function(x, data, env = emptyenv()) {
if (is_call(x, "[[") || is_call(x, "$")) {
if (extract_target_is_likely_data(x, data, env)) {
good_usage <- alternative_aes_extract_usage(x)
warning(
"Use of `", format(x), "` is discouraged. ",
"Use `", good_usage, "` instead.",
call. = FALSE
)
}
} else if (is.call(x)) {
lapply(x, warn_for_aes_extract_usage_expr, data, env)
}
}

alternative_aes_extract_usage <- function(x) {
if (is_call(x, "[[")) {
good_call <- call2("[[", quote(.data), x[[3]])
format(good_call)
} else if (is_call(x, "$")) {
as.character(x[[3]])
} else {
stop("Don't know how to get alternative usage for `", format(x), "`", call. = FALSE)
}
}

extract_target_is_likely_data <- function(x, data, env) {
if (!is.name(x[[2]])) {
return(FALSE)
}

tryCatch({
data_eval <- eval_tidy(x[[2]], data, env)
identical(data_eval, data)
}, error = function(err) FALSE)
}
50 changes: 39 additions & 11 deletions R/axis-secondary.R
Expand Up @@ -187,21 +187,49 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,

# patch for date and datetime scales just to maintain functionality
# works only for linear secondary transforms that respect the time or date transform
if (scale$trans$name %in% c("date", "time")){
if (scale$trans$name %in% c("date", "time")) {
temp_scale <- self$create_scale(new_range, trans = scale$trans)
range_info <- temp_scale$break_info()
names(range_info) <- paste0("sec.", names(range_info))
return(range_info)
}
old_val_trans <- rescale(range_info$major, from = c(0, 1), to = range)
old_val_minor_trans <- rescale(range_info$minor, from = c(0, 1), to = range)
} else {
temp_scale <- self$create_scale(new_range)
range_info <- temp_scale$break_info()

temp_scale <- self$create_scale(new_range)
range_info <- temp_scale$break_info()
# Map the break values back to their correct position on the primary scale
old_val <- lapply(range_info$major_source, function(x) which.min(abs(full_range - x)))
old_val <- old_range[unlist(old_val)]
old_val_trans <- scale$trans$transform(old_val)

old_val_minor <- lapply(range_info$minor_source, function(x) which.min(abs(full_range - x)))
old_val_minor <- old_range[unlist(old_val_minor)]
old_val_minor_trans <- scale$trans$transform(old_val_minor)

# rescale values from 0 to 1
range_info$major[] <- round(
rescale(
scale$map(old_val_trans, range(old_val_trans)),
from = range
),
digits = 3
)

range_info$minor[] <- round(
rescale(
scale$map(old_val_minor_trans, range(old_val_minor_trans)),
from = range
),
digits = 3
)
}

# Map the break values back to their correct position on the primary scale
old_val <- lapply(range_info$major_source, function(x) which.min(abs(full_range - x)))
old_val <- old_range[unlist(old_val)]
old_val_trans <- scale$trans$transform(old_val)
range_info$major[] <- round(rescale(scale$map(old_val_trans, range(old_val_trans)), from = range), digits = 3)
# The _source values should be in (primary) scale_transformed space,
# so that the coord doesn't have to know about the secondary scale transformation
# when drawing the axis. The values in user space are useful for testing.
range_info$major_source_user <- range_info$major_source
range_info$minor_source_user <- range_info$minor_source
range_info$major_source[] <- old_val_trans
range_info$minor_source[] <- old_val_minor_trans

names(range_info) <- paste0("sec.", names(range_info))
range_info
Expand Down
2 changes: 1 addition & 1 deletion R/bin.R
Expand Up @@ -102,7 +102,7 @@ bin_breaks_bins <- function(x_range, bins = 30, center = NULL,
if (bins < 1) {
stop("Need at least one bin.", call. = FALSE)
} else if (zero_range(x_range)) {
# 0.1 is the same width as the expansion `expand_default()` gives for 0-width data
# 0.1 is the same width as the expansion `default_expansion()` gives for 0-width data
width <- 0.1
} else if (bins == 1) {
width <- diff(x_range)
Expand Down

0 comments on commit 8f27d7a

Please sign in to comment.