Skip to content

Commit df5b108

Browse files
authored
Merge pull request #24 from tidyverse/master
Sync Fork from Upstream Repo
2 parents 6a12050 + 7e51849 commit df5b108

File tree

13 files changed

+100
-33
lines changed

13 files changed

+100
-33
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name: R-CMD-check
1010

1111
# Increment this version when we want to clear cache
1212
env:
13-
cache-version: v3
13+
cache-version: v4
1414

1515
jobs:
1616
R-CMD-check:
@@ -24,17 +24,17 @@ jobs:
2424
config:
2525
- {os: windows-latest, r: '4.0', vdiffr: true, xref: true}
2626
- {os: macOS-latest, r: '4.0', vdiffr: true, xref: true}
27-
- {os: ubuntu-16.04, r: 'devel', vdiffr: false, xref: true, cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
28-
- {os: ubuntu-16.04, r: '4.0', vdiffr: true, xref: true, cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
29-
- {os: ubuntu-16.04, r: '3.6', vdiffr: false, xref: true, cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
30-
- {os: ubuntu-16.04, r: '3.5', vdiffr: false, xref: true, cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
31-
- {os: ubuntu-16.04, r: '3.4', vdiffr: false, xref: true, cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
32-
- {os: ubuntu-16.04, r: '3.3', vdiffr: false, xref: true, cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
33-
- {os: ubuntu-16.04, r: '3.2', vdiffr: false, xref: false, cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
27+
- {os: ubuntu-16.04, r: 'devel', vdiffr: false, xref: true}
28+
- {os: ubuntu-16.04, r: '4.0', vdiffr: true, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
29+
- {os: ubuntu-16.04, r: '3.6', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
30+
- {os: ubuntu-16.04, r: '3.5', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
31+
- {os: ubuntu-16.04, r: '3.4', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
32+
- {os: ubuntu-16.04, r: '3.3', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
33+
- {os: ubuntu-16.04, r: '3.2', vdiffr: false, xref: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
3434

3535
env:
3636
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
37-
CRAN: ${{ matrix.config.cran }}
37+
RSPM: ${{ matrix.config.rspm }}
3838
# don't treat missing suggested packages as error
3939
_R_CHECK_FORCE_SUGGESTS_: false
4040
# Some packages might unavailable on the older versions, so let's ignore xref warnings
@@ -49,6 +49,7 @@ jobs:
4949
- uses: r-lib/actions/setup-r@master
5050
with:
5151
r-version: ${{ matrix.config.r }}
52+
http-user-agent: ${{ matrix.config.http-user-agent }}
5253

5354
- uses: r-lib/actions/setup-pandoc@master
5455

@@ -68,12 +69,11 @@ jobs:
6869

6970
- name: Install system dependencies on Linux
7071
if: runner.os == 'Linux'
71-
env:
72-
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
7372
run: |
74-
Rscript -e "remotes::install_github('r-hub/sysreqs')"
75-
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
76-
sudo -s eval "$sysreqs"
73+
while read -r cmd
74+
do
75+
eval sudo $cmd
76+
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "16.04"))')
7777
7878
- name: Install system dependencies on macOS
7979
if: runner.os == 'macOS'

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ Suggests:
6363
sf (>= 0.7-3),
6464
svglite (>= 1.2.0.9001),
6565
testthat (>= 2.1.0),
66-
vdiffr (>= 0.3.0)
66+
vdiffr (>= 0.3.0),
67+
xml2
6768
Enhances: sp
6869
License: GPL-2 | file LICENSE
6970
URL: http://ggplot2.tidyverse.org, https://github.com/tidyverse/ggplot2

NEWS.md

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

3+
* `ggsave()` now sets the default background to match the fill value of the
4+
`plot.background` theme element (@karawoo, #4057)
5+
36
* Extended `stat_ecdf()` to calculate the cdf from either x or y instead from y only (@jgjl, #4005).
47

58
* Fixed a bug in `labeller()` so that `.default` is passed to `as_labeller()`
@@ -13,6 +16,9 @@
1316
`scale_*(guide = FALSE)` to remove a guide. Please use
1417
`guides(<scale> = "none")` or `scale_*(guide = "none")` instead
1518
(@yutannihilation, #4094).
19+
20+
* Date and datetime position scales support out-of-bounds (oob) arguments to
21+
control how limits affect data outside those limits (@teunbrand, #4199).
1622

1723
* `stat_bin()`'s computed variable `width` is now documented (#3522).
1824

R/fortify.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fortify.grouped_df <- function(model, data, ...) {
4141
fortify.default <- function(model, data, ...) {
4242
msg <- paste0(
4343
"`data` must be a data frame, or other object coercible by `fortify()`, ",
44-
"not ", obj_desc(model)
44+
"not ", obj_desc(model), "."
4545
)
4646
if (inherits(model, "uneval")) {
4747
msg <- paste0(

R/quick-plot.r

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,19 @@ qplot <- function(x, y, ..., data, facets = NULL, margins = FALSE,
8989

9090

9191
if (is.null(xlab)) {
92-
xlab <- as_label(exprs$x)
92+
# Avoid <empty> label (#4170)
93+
if (quo_is_missing(exprs$x)) {
94+
xlab <- ""
95+
} else {
96+
xlab <- as_label(exprs$x)
97+
}
9398
}
9499
if (is.null(ylab)) {
95-
ylab <- as_label(exprs$y)
100+
if (quo_is_missing(exprs$y)) {
101+
ylab <- ""
102+
} else {
103+
ylab <- as_label(exprs$y)
104+
}
96105
}
97106

98107
if (missing(data)) {

R/save.r

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#' @param limitsize When `TRUE` (the default), `ggsave()` will not
3939
#' save images larger than 50x50 inches, to prevent the common error of
4040
#' specifying dimensions in pixels.
41+
#' @param bg Background colour. If `NULL`, uses the `plot.background` fill value
42+
#' from the plot theme.
4143
#' @param ... Other arguments passed on to the graphics device function,
4244
#' as specified by `device`.
4345
#' @export
@@ -74,7 +76,7 @@
7476
ggsave <- function(filename, plot = last_plot(),
7577
device = NULL, path = NULL, scale = 1,
7678
width = NA, height = NA, units = c("in", "cm", "mm"),
77-
dpi = 300, limitsize = TRUE, ...) {
79+
dpi = 300, limitsize = TRUE, bg = NULL, ...) {
7880

7981
dpi <- parse_dpi(dpi)
8082
dev <- plot_dev(device, filename, dpi = dpi)
@@ -84,8 +86,11 @@ ggsave <- function(filename, plot = last_plot(),
8486
if (!is.null(path)) {
8587
filename <- file.path(path, filename)
8688
}
89+
if (is_null(bg)) {
90+
bg <- calc_element("plot.background", plot_theme(plot))$fill
91+
}
8792
old_dev <- grDevices::dev.cur()
88-
dev(filename = filename, width = dim[1], height = dim[2], ...)
93+
dev(filename = filename, width = dim[1], height = dim[2], bg = bg, ...)
8994
on.exit(utils::capture.output({
9095
grDevices::dev.off()
9196
if (old_dev > 1) grDevices::dev.set(old_dev) # restore old device unless null device

R/scale-date.r

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ scale_x_date <- function(name = waiver(),
6666
date_minor_breaks = waiver(),
6767
limits = NULL,
6868
expand = waiver(),
69+
oob = censor,
6970
guide = waiver(),
7071
position = "bottom",
7172
sec.axis = waiver()) {
@@ -84,6 +85,7 @@ scale_x_date <- function(name = waiver(),
8485
guide = guide,
8586
limits = limits,
8687
expand = expand,
88+
oob = oob,
8789
position = position
8890
)
8991

@@ -101,6 +103,7 @@ scale_y_date <- function(name = waiver(),
101103
date_minor_breaks = waiver(),
102104
limits = NULL,
103105
expand = waiver(),
106+
oob = censor,
104107
guide = waiver(),
105108
position = "left",
106109
sec.axis = waiver()) {
@@ -119,6 +122,7 @@ scale_y_date <- function(name = waiver(),
119122
guide = guide,
120123
limits = limits,
121124
expand = expand,
125+
oob = oob,
122126
position = position
123127
)
124128

@@ -137,6 +141,7 @@ scale_x_datetime <- function(name = waiver(),
137141
timezone = NULL,
138142
limits = NULL,
139143
expand = waiver(),
144+
oob = censor,
140145
guide = waiver(),
141146
position = "bottom",
142147
sec.axis = waiver()) {
@@ -156,6 +161,7 @@ scale_x_datetime <- function(name = waiver(),
156161
guide = guide,
157162
limits = limits,
158163
expand = expand,
164+
oob = oob,
159165
position = position
160166
)
161167

@@ -175,6 +181,7 @@ scale_y_datetime <- function(name = waiver(),
175181
timezone = NULL,
176182
limits = NULL,
177183
expand = waiver(),
184+
oob = censor,
178185
guide = waiver(),
179186
position = "left",
180187
sec.axis = waiver()) {
@@ -194,6 +201,7 @@ scale_y_datetime <- function(name = waiver(),
194201
guide = guide,
195202
limits = limits,
196203
expand = expand,
204+
oob = oob,
197205
position = position
198206
)
199207

R/scale-hue.r

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ scale_fill_hue <- function(..., h = c(0, 360) + 15, c = 100, l = 65, h.start = 0
7676
#' * A character vector of color codes. The codes are used for a 'manual' color
7777
#' scale as long as the number of codes exceeds the number of data levels
7878
#' (if there are more levels than codes, [scale_colour_hue()]/[scale_fill_hue()]
79-
#' are used to construct the default scale).
79+
#' are used to construct the default scale). If this is a named vector, then the color values
80+
#' will be matched to levels based on the names of the vectors. Data values that
81+
#' don't match will be set as `na.value`.
8082
#' * A list of character vectors of color codes. The minimum length vector that exceeds the
8183
#' number of data levels is chosen for the color scaling. This is useful if you
8284
#' want to change the color palette based on the number of levels.

man/ggsave.Rd

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

man/scale_colour_discrete.Rd

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

man/scale_date.Rd

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

tests/testthat/helper-vdiffr.R

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@
22
# - VDIFFR_RUN_TESTS is "false" (on Travis CI with older versions and dev version of R)
33
# - CI is not set (on CRAN)
44

5-
expect_doppelganger <- vdiffr::expect_doppelganger
5+
if (requireNamespace("vdiffr", quietly = TRUE)) {
6+
expect_doppelganger <- vdiffr::expect_doppelganger
7+
} else {
8+
# If vdiffr is not available and visual tests are not explicitly disabled, raise error.
9+
if (!identical(Sys.getenv("VDIFFR_RUN_TESTS"), "false")) {
10+
abort("vdiffr is not installed")
11+
}
12+
13+
# Otherwise, assign a dummy function
14+
expect_doppelganger <- function(...) skip("vdiffr is not installed.")
15+
}

tests/testthat/test-ggsave.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ test_that("ggsave restores previous graphics device", {
2828
expect_identical(old_dev, dev.cur())
2929
})
3030

31+
test_that("ggsave uses theme background as image background", {
32+
skip_if_not_installed("xml2")
33+
34+
path <- tempfile()
35+
on.exit(unlink(path))
36+
p <- ggplot(mtcars, aes(disp, mpg)) +
37+
geom_point() +
38+
coord_fixed() +
39+
theme(plot.background = element_rect(fill = "#00CCCC"))
40+
ggsave(path, p, device = "svg", width = 5, height = 5)
41+
img <- xml2::read_xml(path)
42+
# Find background rect in svg
43+
bg <- as.character(xml2::xml_find_first(img, xpath = "d1:rect/@style"))
44+
expect_true(grepl("fill: #00CCCC", bg))
45+
})
46+
3147
# plot_dim ---------------------------------------------------------------
3248

3349
test_that("guesses and informs if dim not specified", {

0 commit comments

Comments
 (0)