Skip to content

Commit 5b58c7c

Browse files
authored
Merge branch 'main' into v3.4.1-rc
2 parents baad4cc + 37d9e8c commit 5b58c7c

19 files changed

+498
-111
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: Bug report
3+
about: Submit a bug report to help us improve ggplot2
4+
---
5+
6+
### Tips for a helpful bug report:
7+
8+
* If you have a question, please don't use this form. Instead, ask on <https://stackoverflow.com/> or <https://community.rstudio.com/>.
9+
10+
* Please include a **minimal reproducible example**, a reprex, to demonstrate the bug.
11+
If you've never heard of a reprex, please read ["Make a reprex"](https://www.tidyverse.org/help/#reprex).
12+
Do not include session info unless it is explicitly asked for.
13+
14+
* If you can, use one of the built-in datasets or a small toy dataset that exposes the bug.
15+
If for some reason, the bug only occurs on your original data, try to limit the number of rows that are necessary to expose the bug.
16+
Share such data by copying `dput()` output rather than an external file.
17+
18+
* Unless the bug is about the theme, labels, scales or other plot decoration: please omit these from the code.
19+
20+
* Please check whether somebody has reported the same problem in the [issues](https://github.com/tidyverse/ggplot2/issues).
21+
22+
Delete these instructions once you have read them.
23+
24+
---
25+
26+
I found a problem with ...
27+
28+
I expected ...
29+
30+
Here is the code to reproduce the bug:
31+
32+
```r
33+
# copy your code to the clipboard and run:
34+
reprex::reprex()
35+
```

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
contact_links:
2+
- name: Help or discussion
3+
url: https://community.rstudio.com/
4+
about: "Check out options for getting help on the RStudio Community."
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: "Feature Request"
3+
about: Suggest a change or new feature in ggplot2
4+
---
5+
6+
### Tips for a helpful feature request:
7+
8+
* If you have a question, please don't use this form. Instead, ask on <https://stackoverflow.com/> or <https://community.rstudio.com/>.
9+
10+
* See the [contributing guidelines](https://github.com/tidyverse/ggplot2/blob/main/CONTRIBUTING.md).
11+
12+
* ggplot2 is a mature package that is unlikely to adopt new functionality that can be covered by its extension mechanisms.
13+
Improvements to its current functionality or to infrastructure are considered in scope for feature requests.
14+
15+
* Please motivate the need for change, if applicable with a **minimal reproducible** example (reprex).
16+
If you've never heard of a reprex, please read ["Make a reprex"](https://www.tidyverse.org/help/#reprex).
17+
Do not include session info unless it is explicitly asked for.
18+
19+
Delete this instructions once you've read them.
20+
21+
---
22+
23+
In situations when ...
24+
25+
I would like to be able to ...
26+
27+
```r
28+
# copy your code to the clipboard and run:
29+
reprex::reprex()
30+
```

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959

6060
- uses: r-lib/actions/setup-r-dependencies@v2
6161
with:
62-
cache-version: 2
62+
cache-version: 3
6363
extra-packages: >
6464
any::rcmdcheck,
6565
Hmisc=?ignore-before-r=3.6.0,

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Config/testthat/edition: 3
8080
Encoding: UTF-8
8181
LazyData: true
8282
Roxygen: list(markdown = TRUE)
83-
RoxygenNote: 7.2.1
83+
RoxygenNote: 7.2.3
8484
Collate:
8585
'ggproto.r'
8686
'ggplot-global.R'

ISSUE_TEMPLATE.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ S3method(scale_type,Date)
132132
S3method(scale_type,POSIXt)
133133
S3method(scale_type,character)
134134
S3method(scale_type,default)
135+
S3method(scale_type,double)
135136
S3method(scale_type,factor)
136137
S3method(scale_type,hms)
138+
S3method(scale_type,integer)
137139
S3method(scale_type,list)
138140
S3method(scale_type,logical)
139141
S3method(scale_type,numeric)
@@ -316,6 +318,7 @@ export(coord_trans)
316318
export(cut_interval)
317319
export(cut_number)
318320
export(cut_width)
321+
export(datetime_scale)
319322
export(derive)
320323
export(discrete_scale)
321324
export(draw_key_abline)

NEWS.md

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

3+
* Fixed bug in `coord_sf()` where graticule lines didn't obey
4+
`panel.grid.major`'s linewidth setting (@teunbrand, #5179)
5+
* The `datetime_scale()` scale constructor is now exported for use in extension
6+
packages (@teunbrand, #4701).
7+
* `geom_text()` drops observations where `angle = NA` instead of throwing an
8+
error (@teunbrand, #2757).
9+
* `update_geom_defaults()` and `update_stat_defaults()` now return properly
10+
classed objects and have updated docs (@dkahle, #5146)
11+
312
# ggplot2 3.4.1
413
This is a small release focusing on fixing regressions in the 3.4.0 release
514
and minor polishes.

R/coord-sf.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
305305
} else {
306306
line_gp <- gpar(
307307
col = el$colour,
308-
lwd = len0_null(el$size*.pt),
308+
lwd = len0_null(el$linewidth * .pt),
309309
lty = el$linetype
310310
)
311311
grobs <- c(

R/geom-defaults.r

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,38 @@
77
#' @keywords internal
88
#' @export
99
#' @examples
10-
#' update_geom_defaults("point", list(colour = "darkblue"))
10+
#'
11+
#' # updating a geom's default aesthetic settings
12+
#' # example: change geom_point()'s default color
13+
#' GeomPoint$default_aes
14+
#' update_geom_defaults("point", aes(color = "red"))
15+
#' GeomPoint$default_aes
1116
#' ggplot(mtcars, aes(mpg, wt)) + geom_point()
12-
#' update_geom_defaults("point", list(colour = "black"))
17+
#'
18+
#' # reset default
19+
#' update_geom_defaults("point", aes(color = "black"))
20+
#'
21+
#'
22+
#' # updating a stat's default aesthetic settings
23+
#' # example: change stat_bin()'s default y-axis to the density scale
24+
#' StatBin$default_aes
25+
#' update_stat_defaults("bin", aes(y = after_stat(density)))
26+
#' StatBin$default_aes
27+
#' ggplot(data.frame(x = rnorm(1e3)), aes(x)) +
28+
#' geom_histogram() +
29+
#' geom_function(fun = dnorm, color = "red")
30+
#'
31+
#' # reset default
32+
#' update_stat_defaults("bin", aes(y = after_stat(count)))
33+
#'
1334
#' @rdname update_defaults
1435
update_geom_defaults <- function(geom, new) {
1536
g <- check_subclass(geom, "Geom", env = parent.frame())
1637
old <- g$default_aes
17-
g$default_aes <- defaults(rename_aes(new), old)
38+
new <- rename_aes(new)
39+
new_names_order <- unique(c(names(old), names(new)))
40+
new <- defaults(new, old)[new_names_order]
41+
g$default_aes[names(new)] <- new
1842
invisible()
1943
}
2044

@@ -23,6 +47,9 @@ update_geom_defaults <- function(geom, new) {
2347
update_stat_defaults <- function(stat, new) {
2448
g <- check_subclass(stat, "Stat", env = parent.frame())
2549
old <- g$default_aes
26-
g$default_aes <- defaults(rename_aes(new), old)
50+
new <- rename_aes(new)
51+
new_names_order <- unique(c(names(old), names(new)))
52+
new <- defaults(new, old)[new_names_order]
53+
g$default_aes[names(new)] <- new
2754
invisible()
2855
}

R/geom-text.r

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
#' df <- data.frame(
146146
#' x = c(1, 1, 2, 2, 1.5),
147147
#' y = c(1, 2, 1, 2, 1.5),
148-
#' text = c("bottom-left", "bottom-right", "top-left", "top-right", "center")
148+
#' text = c("bottom-left", "top-left", "bottom-right", "top-right", "center")
149149
#' )
150150
#' ggplot(df, aes(x, y)) +
151151
#' geom_text(aes(label = text))
@@ -198,6 +198,8 @@ geom_text <- function(mapping = NULL, data = NULL,
198198
GeomText <- ggproto("GeomText", Geom,
199199
required_aes = c("x", "y", "label"),
200200

201+
non_missing_aes = "angle",
202+
201203
default_aes = aes(
202204
colour = "black", size = 3.88, angle = 0, hjust = 0.5,
203205
vjust = 0.5, alpha = NA, family = "", fontface = 1, lineheight = 1.2

R/plot.r

Lines changed: 73 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,35 @@
66
#' subsequent layers unless specifically overridden.
77
#'
88
#' `ggplot()` is used to construct the initial plot object,
9-
#' and is almost always followed by `+` to add component to the
10-
#' plot. There are three common ways to invoke `ggplot()`:
9+
#' and is almost always followed by a plus sign (`+`) to add
10+
#' components to the plot.
1111
#'
12-
#' * `ggplot(df, aes(x, y, other aesthetics))`
13-
#' * `ggplot(df)`
12+
#' There are three common patterns used to invoke `ggplot()`:
13+
#'
14+
#' * `ggplot(data = df, mapping = aes(x, y, other aesthetics))`
15+
#' * `ggplot(data = df)`
1416
#' * `ggplot()`
1517
#'
16-
#' The first method is recommended if all layers use the same
18+
#' The first pattern is recommended if all layers use the same
1719
#' data and the same set of aesthetics, although this method
18-
#' can also be used to add a layer using data from another
19-
#' data frame. See the first example below. The second
20-
#' method specifies the default data frame to use for the plot,
21-
#' but no aesthetics are defined up front. This is useful when
22-
#' one data frame is used predominantly as layers are added,
23-
#' but the aesthetics may vary from one layer to another. The
24-
#' third method initializes a skeleton `ggplot` object which
25-
#' is fleshed out as layers are added. This method is useful when
20+
#' can also be used when adding a layer using data from another
21+
#' data frame.
22+
#'
23+
#' The second pattern specifies the default data frame to use
24+
#' for the plot, but no aesthetics are defined up front. This
25+
#' is useful when one data frame is used predominantly for the
26+
#' plot, but the aesthetics vary from one layer to another.
27+
#'
28+
#' The third pattern initializes a skeleton `ggplot` object, which
29+
#' is fleshed out as layers are added. This is useful when
2630
#' multiple data frames are used to produce different layers, as
2731
#' is often the case in complex graphics.
2832
#'
33+
#' The `data =` and `mapping =` specifications in the arguments are optional
34+
#' (and are often omitted in practice), so long as the data and the mapping
35+
#' values are passed into the function in the right order. In the examples
36+
#' below, however, they are left in place for clarity.
37+
#'
2938
#' @param data Default dataset to use for plot. If not already a data.frame,
3039
#' will be converted to one by [fortify()]. If not specified,
3140
#' must be supplied in each layer added to the plot.
@@ -36,42 +45,61 @@
3645
#' evaluation.
3746
#' @export
3847
#' @examples
39-
#' # Generate some sample data, then compute mean and standard deviation
40-
#' # in each group
48+
#' # Create a data frame with some sample data, then create a data frame
49+
#' # containing the mean value for each group in the sample data.
4150
#' set.seed(1)
42-
#' df <- data.frame(
43-
#' gp = factor(rep(letters[1:3], each = 10)),
44-
#' y = rnorm(30)
51+
#'
52+
#' sample_df <- data.frame(
53+
#' group = factor(rep(letters[1:3], each = 10)),
54+
#' value = rnorm(30)
4555
#' )
46-
#' ds <- do.call(rbind, lapply(split(df, df$gp), function(d) {
47-
#' data.frame(mean = mean(d$y), sd = sd(d$y), gp = d$gp)
48-
#' }))
49-
#'
50-
#' # The summary data frame ds is used to plot larger red points on top
51-
#' # of the raw data. Note that we don't need to supply `data` or `mapping`
52-
#' # in each layer because the defaults from ggplot() are used.
53-
#' ggplot(df, aes(gp, y)) +
56+
#'
57+
#' group_means_df <- setNames(
58+
#' aggregate(value ~ group, sample_df, mean),
59+
#' c("group", "group_mean")
60+
#' )
61+
#'
62+
#' # The following three code blocks create the same graphic, each using one
63+
#' # of the three patterns specified above. In each graphic, the sample data
64+
#' # are plotted in the first layer and the group means data frame is used to
65+
#' # plot larger red points on top of the sample data in the second layer.
66+
#'
67+
#' # Pattern 1
68+
#' # Both the `data` and `mapping` arguments are passed into the `ggplot()`
69+
#' # call. Those arguments are omitted in the first `geom_point()` layer
70+
#' # because they get passed along from the `ggplot()` call. Note that the
71+
#' # second `geom_point()` layer re-uses the `x = group` aesthetic through
72+
#' # that mechanism but overrides the y-position aesthetic.
73+
#' ggplot(data = sample_df, mapping = aes(x = group, y = value)) +
5474
#' geom_point() +
55-
#' geom_point(data = ds, aes(y = mean), colour = 'red', size = 3)
56-
#'
57-
#' # Same plot as above, declaring only the data frame in ggplot().
58-
#' # Note how the x and y aesthetics must now be declared in
59-
#' # each geom_point() layer.
60-
#' ggplot(df) +
61-
#' geom_point(aes(gp, y)) +
62-
#' geom_point(data = ds, aes(gp, mean), colour = 'red', size = 3)
63-
#'
64-
#' # Alternatively we can fully specify the plot in each layer. This
65-
#' # is not useful here, but can be more clear when working with complex
66-
#' # mult-dataset graphics
75+
#' geom_point(
76+
#' mapping = aes(y = group_mean), data = group_means_df,
77+
#' colour = 'red', size = 3
78+
#' )
79+
#'
80+
#' # Pattern 2
81+
#' # Same plot as above, passing only the `data` argument into the `ggplot()`
82+
#' # call. The `mapping` arguments are now required in each `geom_point()`
83+
#' # layer because there is no `mapping` argument passed along from the
84+
#' # `ggplot()` call.
85+
#' ggplot(data = sample_df) +
86+
#' geom_point(mapping = aes(x = group, y = value)) +
87+
#' geom_point(
88+
#' mapping = aes(x = group, y = group_mean), data = group_means_df,
89+
#' colour = 'red', size = 3
90+
#' )
91+
#'
92+
#' # Pattern 3
93+
#' # Same plot as above, passing neither the `data` or `mapping` arguments
94+
#' # into the `ggplot()` call. Both those arguments are now required in
95+
#' # each `geom_point()` layer. This pattern can be particularly useful when
96+
#' # creating more complex graphics with many layers using data from multiple
97+
#' # data frames.
6798
#' ggplot() +
68-
#' geom_point(data = df, aes(gp, y)) +
69-
#' geom_point(data = ds, aes(gp, mean), colour = 'red', size = 3) +
70-
#' geom_errorbar(
71-
#' data = ds,
72-
#' aes(gp, mean, ymin = mean - sd, ymax = mean + sd),
73-
#' colour = 'red',
74-
#' width = 0.4
99+
#' geom_point(mapping = aes(x = group, y = value), data = sample_df) +
100+
#' geom_point(
101+
#' mapping = aes(x = group, y = group_mean), data = group_means_df,
102+
#' colour = 'red', size = 3
75103
#' )
76104
ggplot <- function(data = NULL, mapping = aes(), ...,
77105
environment = parent.frame()) {

R/scale-date.r

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,16 @@ scale_y_time <- function(name = waiver(),
275275
)
276276
}
277277

278-
## rename to datetime_scale
278+
#' Date/time scale constructor
279+
#'
280+
#' @inheritParams scale_x_datetime
281+
#' @inheritParams continuous_scale
282+
#' @param trans For date/time scales, the name of a date/time transformation or
283+
#' the object itself. Built-in transformations include "hms", "date" and "time".
284+
#' @inheritDotParams continuous_scale -aesthetics -trans -palette -breaks -minor_breaks -labels -guide
285+
#'
286+
#' @export
287+
#' @keywords internal
279288
datetime_scale <- function(aesthetics, trans, palette,
280289
breaks = pretty_breaks(), minor_breaks = waiver(),
281290
labels = waiver(), date_breaks = waiver(),

R/scale-type.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,11 @@ scale_type.Date <- function(x) c("date", "continuous")
9191
#' @export
9292
scale_type.numeric <- function(x) "continuous"
9393

94+
#' @export
95+
scale_type.integer <- function(x) "continuous"
96+
97+
#' @export
98+
scale_type.double <- function(x) "continuous"
99+
94100
#' @export
95101
scale_type.hms <- function(x) "time"

0 commit comments

Comments
 (0)