Skip to content

Commit

Permalink
Merge branch 'master' into mikmart-tidyverse#2488-hex-aes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikmart committed Jul 9, 2018
2 parents 343a38f + d506990 commit 8a543b8
Show file tree
Hide file tree
Showing 42 changed files with 4,931 additions and 6,364 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
^CRAN-RELEASE$
visual_test
^.*\.Rproj$
^\.Rproj\.user$
Expand All @@ -19,3 +20,4 @@ visual_test
^README-.*\.png$
^logo\.png$
^appveyor\.yml$
^\.github$
31 changes: 31 additions & 0 deletions .github/lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Configuration for lock-threads - https://github.com/dessant/lock-threads

# Number of days of inactivity before a closed issue or pull request is locked
daysUntilLock: 180

# Issues and pull requests with these labels will not be locked. Set to `[]` to disable
exemptLabels: []

# Label to add before locking, such as `outdated`. Set to `false` to disable
lockLabel: false

# Comment to post before locking. Set to `false` to disable
lockComment: >
This old issue has been automatically locked. If you believe you
have found a related problem, please file a new issue (with reprex)
and link to this issue. <https://reprex.tidyverse.org/>
# Stop lockbot from closing as "resolved"
setLockReason: false

# Limit to only `issues` or `pulls`
# only: issues

# Optionally, specify configuration settings just for `issues` or `pulls`
# issues:
# exemptLabels:
# - help-wanted
# lockLabel: outdated

# pulls:
# daysUntilLock: 30
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: ggplot2
Version: 2.2.1.9000
Version: 3.0.0.9000
Title: Create Elegant Data Visualisations Using the Grammar of Graphics
Description: A system for 'declaratively' creating graphics,
based on "The Grammar of Graphics". You provide the data, tell 'ggplot2'
Expand All @@ -26,7 +26,7 @@ Imports:
mgcv,
plyr (>= 1.7.1),
reshape2,
rlang,
rlang (>= 0.2.1),
scales (>= 0.5.0),
stats,
tibble,
Expand Down Expand Up @@ -61,6 +61,7 @@ BugReports: https://github.com/tidyverse/ggplot2/issues
LazyData: true
Collate:
'ggproto.r'
'ggplot-global.R'
'aaa-.r'
'aes-calculated.r'
'aes-colour-fill-alpha.r'
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ S3method(fortify,glht)
S3method(fortify,grouped_df)
S3method(fortify,lm)
S3method(fortify,map)
S3method(fortify,sfc)
S3method(fortify,sfg)
S3method(fortify,summary.glht)
S3method(fortify,tbl)
S3method(fortify,tbl_df)
S3method(ggplot,"function")
S3method(ggplot,default)
S3method(ggplot_add,"NULL")
Expand Down
30 changes: 17 additions & 13 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# ggplot2 3.0.0.9000

* `geom_hex()` now understands the `size` and `linetype` aesthetics
(@mikmart, #2488).

# ggplot2 2.2.1.9000
To be released as 2.3.0

# ggplot2 3.0.0

## Breaking changes

Expand All @@ -13,16 +14,19 @@ To be released as 2.3.0
introduction to tidy evaluation can be found in the meta programming
chapters in [Advanced R](https://adv-r.hadley.nz).

The primary developer facing change is that `aes()` is now a list of
quosures (expression + environment pairs) rather than a list of symbols,
and you'll need to take a different approach to extracting the information
you need. A common symptom of this change are errors "undefined columns
selected" or "invalid 'type' (list) of argument" (#2610).
The primary developer facing change is that `aes()` now contains
quosures (expression + environment pairs) rather than symbols, and you'll
need to take a different approach to extracting the information you need.
A common symptom of this change are errors "undefined columns selected" or
"invalid 'type' (list) of argument" (#2610). As in the previous version,
constants (like `aes(x = 1)` or `aes(colour = "smoothed")`) are stored
as is.

In this version of ggplot2, you need to describe a mapping in a string,
use `quo_name()` (for shorter labels) or `quo_text()` (if you want
everything). If you do need to extract the value of a variable instead use
`rlang::eval_tidy()`. You may want to condition on
In this version of ggplot2, if you need to describe a mapping in a string,
use `quo_name()` (to generate single-line strings; longer expressions may
be abbreviated) or `quo_text()` (to generate non-abbreviated strings that
may span multiple lines). If you do need to extract the value of a variable
instead use `rlang::eval_tidy()`. You may want to condition on
`(packageVersion("ggplot2") <= "2.2.1")` so that your code can work with
both released and development versions of ggplot2.

Expand Down Expand Up @@ -55,7 +59,7 @@ To be released as 2.3.0
data frame. Each aesthetic now must be either the same length as the data
frame or a single value. This makes silent recycling errors much less likely.

* Error: Free scales are only supported with `coord_cartesian()` and `coord_flip()`
* Error: `coord_*` doesn't support free scales

Free scales only work with selected coordinate systems; previously you'd
get an incorrect plot.
Expand Down
1 change: 1 addition & 0 deletions R/aaa-.r
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @include ggplot-global.R
#' @include ggproto.r
NULL

Expand Down
53 changes: 19 additions & 34 deletions R/aes.r
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
#' @include utilities.r
NULL

.all_aesthetics <- c("adj", "alpha", "angle", "bg", "cex", "col", "color",
"colour", "fg", "fill", "group", "hjust", "label", "linetype", "lower",
"lty", "lwd", "max", "middle", "min", "pch", "radius", "sample", "shape",
"size", "srt", "upper", "vjust", "weight", "width", "x", "xend", "xmax",
"xmin", "xintercept", "y", "yend", "ymax", "ymin", "yintercept", "z")

.base_to_ggplot <- c(
"col" = "colour",
"color" = "colour",
"pch" = "shape",
"cex" = "size",
"lty" = "linetype",
"lwd" = "size",
"srt" = "angle",
"adj" = "hjust",
"bg" = "fill",
"fg" = "colour",
"min" = "ymin",
"max" = "ymax"
)

#' Construct aesthetic mappings
#'
#' Aesthetic mappings describe how variables in the data are mapped to visual
Expand All @@ -48,6 +27,8 @@ NULL
#' 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
#' quosures or constants.
#' @export
#' @examples
#' aes(x = mpg, y = wt)
Expand All @@ -56,32 +37,36 @@ NULL
#' # You can also map aesthetics to functions of variables
#' aes(x = mpg ^ 2, y = wt / cyl)
#'
#' # Or to constants
#' aes(x = 1, colour = "smooth")
#'
#' # Aesthetic names are automatically standardised
#' aes(col = x)
#' aes(fg = x)
#' aes(color = x)
#' aes(colour = x)
#'
#' # aes is almost always used with ggplot() or a layer
#' # aes() is passed to either ggplot() or specific layer. Aesthetics supplied
#' # to ggplot() are used as defaults for every layer.
#' ggplot(mpg, aes(displ, hwy)) + geom_point()
#' ggplot(mpg) + geom_point(aes(displ, hwy))
#'
#' # Aesthetics supplied to ggplot() are used as defaults for every layer
#' # you can override them, or supply different aesthetics for each layer
#'
#'
#' # aes() is a quoting function, so you need to use tidy evaluation
#' # techniques to create wrappers around ggplot2 pipelines. The
#' # Tidy evaluation ----------------------------------------------------
#' # aes() automatically quotes all its arguments, so you need to use tidy
#' # evaluation to create wrappers around ggplot2 pipelines. The
#' # simplest case occurs when your wrapper takes dots:
#' scatter_by <- function(data, ...) {
#' ggplot(data) + geom_point(aes(...))
#' }
#' scatter_by(mtcars, disp, drat)
#'
#' # If your wrapper has a more specific interface with named arguments,
#' # you need to use the "enquote and unquote" technique:
#' # you need "enquote and unquote":
#' scatter_by <- function(data, x, y) {
#' ggplot(data) + geom_point(aes(!!enquo(x), !!enquo(y)))
#' x <- enquo(x)
#' y <- enquo(y)
#'
#' ggplot(data) + geom_point(aes(!!x, !!y))
#' }
#' scatter_by(mtcars, disp, drat)
#'
Expand Down Expand Up @@ -161,10 +146,10 @@ print.uneval <- function(x, ...) {
# Rename American or old-style aesthetics name
rename_aes <- function(x) {
# Convert prefixes to full names
full <- match(names(x), .all_aesthetics)
names(x)[!is.na(full)] <- .all_aesthetics[full[!is.na(full)]]
full <- match(names(x), ggplot_global$all_aesthetics)
names(x)[!is.na(full)] <- ggplot_global$all_aesthetics[full[!is.na(full)]]

plyr::rename(x, .base_to_ggplot, warn_missing = FALSE)
plyr::rename(x, ggplot_global$base_to_ggplot, warn_missing = FALSE)
}

# Look up the scale that should be used for a given aesthetic
Expand Down Expand Up @@ -309,7 +294,7 @@ aes_auto <- function(data = NULL, ...) {
}

# automatically detected aes
vars <- intersect(.all_aesthetics, vars)
vars <- intersect(ggplot_global$all_aesthetics, vars)
names(vars) <- vars
aes <- lapply(vars, function(x) parse(text = x)[[1]])

Expand Down
13 changes: 13 additions & 0 deletions R/fortify-spatial.r
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,16 @@ fortify.Line <- function(model, data, ...) {
df$order <- 1:nrow(df)
df
}


#' @export
#' @method fortify sfc
fortify.sfc <- function(model, data, ...) {
sf::st_sf(geometry = model)
}

#' @export
#' @method fortify sfg
fortify.sfg <- function(model, data, ...) {
sf::st_sf(geometry = sf::st_sfc(model))
}
9 changes: 8 additions & 1 deletion R/fortify.r
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ fortify <- function(model, data, ...) UseMethod("fortify")
#' @export
fortify.data.frame <- function(model, data, ...) model
#' @export
fortify.tbl <- function(model, data, ...) dplyr::collect(model)
fortify.tbl_df <- function(model, data, ...) model
#' @export
fortify.tbl <- function(model, data, ...) {
if (!requireNamespace("dplyr", quietly = TRUE)) {
stop("dplyr must be installed to work with tbl objects", call. = FALSE)
}
dplyr::collect(model)
}
#' @export
fortify.NULL <- function(model, data, ...) waiver()
#' @export
Expand Down
5 changes: 5 additions & 0 deletions R/geom-bar.r
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ geom_bar <- function(mapping = NULL, data = NULL,
GeomBar <- ggproto("GeomBar", GeomRect,
required_aes = c("x", "y"),

# These aes columns are created by setup_data(). They need to be listed here so
# that GeomRect$handle_na() properly removes any bars that fall outside the defined
# limits, not just those for which x and y are outside the limits
non_missing_aes = c("xmin", "xmax", "ymin", "ymax"),

setup_data = function(data, params) {
data$width <- data$width %||%
params$width %||% (resolution(data$x, FALSE) * 0.9)
Expand Down
7 changes: 7 additions & 0 deletions R/geom-boxplot.r
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
#'
#' In the unlikely event you specify both US and UK spellings of colour, the
#' US spelling will take precedence.
#'
#' Sometimes it can be useful to hide the outliers, for example when overlaying
#' the raw data points on top of the boxplot. Hiding the outliers can be achieved
#' by setting `outlier.shape = NA`. Importantly, this does not remove the outliers,
#' it only hides them, so the range calculated for the y-axis will be the
#' same with outliers shown and outliers hidden.
#'
#' @param notch If `FALSE` (default) make a standard box plot. If
#' `TRUE`, make a notched box plot. Notches are used to compare groups;
#' if the notches of two boxes do not overlap, this suggests that the medians
Expand Down
5 changes: 5 additions & 0 deletions R/geom-col.r
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ geom_col <- function(mapping = NULL, data = NULL,
GeomCol <- ggproto("GeomCol", GeomRect,
required_aes = c("x", "y"),

# These aes columns are created by setup_data(). They need to be listed here so
# that GeomRect$handle_na() properly removes any bars that fall outside the defined
# limits, not just those for which x and y are outside the limits
non_missing_aes = c("xmin", "xmax", "ymin", "ymax"),

setup_data = function(data, params) {
data$width <- data$width %||%
params$width %||% (resolution(data$x, FALSE) * 0.9)
Expand Down
3 changes: 2 additions & 1 deletion R/geom-point.r
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ GeomPoint <- ggproto("GeomPoint", Geom,
)

translate_shape_string <- function(shape_string) {
if (nchar(shape_string[1]) == 1) {
# strings of length 0 or 1 are interpreted as symbols by grid
if (nchar(shape_string[1]) <= 1) {
return(shape_string)
}

Expand Down
38 changes: 38 additions & 0 deletions R/ggplot-global.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Environment that holds various global variables and settings for ggplot,
# such as the current theme. It is not exported and should not be directly
# manipulated by other packages.
ggplot_global <- new.env(parent = emptyenv())

# The current theme. Defined here only as placeholder, and defined properly
# in file "theme-current.R". This setup avoids circular dependencies among
# the various source files.
ggplot_global$theme_current <- list()

# Element tree for the theme elements. Defined here only as placeholder, and
# defined properly in file "theme-elements.r".
ggplot_global$element_tree <- list()

# List of all aesthetics known to ggplot
ggplot_global$all_aesthetics <- c(
"adj", "alpha", "angle", "bg", "cex", "col", "color",
"colour", "fg", "fill", "group", "hjust", "label", "linetype", "lower",
"lty", "lwd", "max", "middle", "min", "pch", "radius", "sample", "shape",
"size", "srt", "upper", "vjust", "weight", "width", "x", "xend", "xmax",
"xmin", "xintercept", "y", "yend", "ymax", "ymin", "yintercept", "z"
)

# Aesthetic aliases
ggplot_global$base_to_ggplot <- c(
"col" = "colour",
"color" = "colour",
"pch" = "shape",
"cex" = "size",
"lty" = "linetype",
"lwd" = "size",
"srt" = "angle",
"adj" = "hjust",
"bg" = "fill",
"fg" = "colour",
"min" = "ymin",
"max" = "ymax"
)
4 changes: 2 additions & 2 deletions R/guides-.r
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ guides_build <- function(ggrobs, theme) {
yjust <- just[2]

# setting that is different for vertical and horizontal guide-boxes.
if (theme$legend.box == "horizontal") {
if (identical(theme$legend.box, "horizontal")) {
# Set justification for each legend
for (i in seq_along(ggrobs)) {
ggrobs[[i]] <- editGrob(ggrobs[[i]],
Expand All @@ -263,7 +263,7 @@ guides_build <- function(ggrobs, theme) {
# add space between the guide-boxes
guides <- gtable_add_col_space(guides, theme$legend.spacing.x)

} else if (theme$legend.box == "vertical") {
} else { # theme$legend.box == "vertical"
# Set justification for each legend
for (i in seq_along(ggrobs)) {
ggrobs[[i]] <- editGrob(ggrobs[[i]],
Expand Down
Loading

0 comments on commit 8a543b8

Please sign in to comment.