Skip to content

Use scales::label_* over scales::*format()` #5504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/annotation-logticks.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
#' # plotting it. Also hide the minor grid lines.
#' b <- ggplot(msleep, aes(log10(bodywt), log10(brainwt))) +
#' geom_point(na.rm = TRUE) +
#' scale_x_continuous(name = "body", labels = scales::math_format(10^.x)) +
#' scale_y_continuous(name = "brain", labels = scales::math_format(10^.x)) +
#' scale_x_continuous(name = "body", labels = scales::label_math(10^.x)) +
#' scale_y_continuous(name = "brain", labels = scales::label_math(10^.x)) +
#' theme_bw() + theme(panel.grid.minor = element_blank())
#'
#' b + annotation_logticks()
Expand Down
4 changes: 2 additions & 2 deletions R/axis-secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#' date_breaks = "6 hour",
#' sec.axis = dup_axis(
#' name = "Time of Day",
#' labels = scales::time_format("%I %p")
#' labels = scales::label_time("%I %p")
#' )
#' )
#'
Expand All @@ -89,7 +89,7 @@
#' sec.axis = sec_axis(
#' ~ . + 8 * 3600,
#' name = "GMT+8",
#' labels = scales::time_format("%b %d %I %p")
#' labels = scales::label_time("%b %d %I %p")
#' )
#' )
#'
Expand Down
2 changes: 1 addition & 1 deletion R/coord-map.R
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ CoordMap <- ggproto("CoordMap", Coord,


mproject <- function(coord, x, y, orientation) {
check_installed("mapproj", reason = "for `coord_map()`")
check_installed("mapproj", reason = "for `coord_map()`.")
suppressWarnings(mapproj::mapproject(x, y,
projection = coord$projection,
parameters = coord$params,
Expand Down
2 changes: 1 addition & 1 deletion R/fortify-map.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fortify.map <- function(model, data, ...) {
#' coord_map("albers", lat0 = 45.5, lat1 = 29.5)
#' }
map_data <- function(map, region = ".", exact = FALSE, ...) {
check_installed("maps", reason = "for `map_data()`")
check_installed("maps", reason = "for `map_data()`.")
map_obj <- maps::map(map, region, exact = exact, plot = FALSE, fill = TRUE, ...)
fortify(map_obj)
}
Expand Down
4 changes: 2 additions & 2 deletions R/fortify.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fortify.data.frame <- function(model, data, ...) model
fortify.tbl_df <- function(model, data, ...) model
#' @export
fortify.tbl <- function(model, data, ...) {
check_installed("dplyr", reason = "to work with `tbl` objects")
check_installed("dplyr", reason = "to work with `tbl` objects.")
dplyr::collect(model)
}
#' @export
Expand All @@ -29,7 +29,7 @@ fortify.function <- function(model, data, ...) model
fortify.formula <- function(model, data, ...) as_function(model)
#' @export
fortify.grouped_df <- function(model, data, ...) {
check_installed("dplyr", reason = "to work with `grouped_df` objects")
check_installed("dplyr", reason = "to work with `grouped_df` objects.")
model$.group <- dplyr::group_indices(model)
model
}
Expand Down
6 changes: 3 additions & 3 deletions R/scale-continuous.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
#' y = seq(0, 1, length.out = 10)
#' )
#' p2 <- ggplot(df, aes(x, y)) + geom_point()
#' p2 + scale_y_continuous(labels = scales::percent)
#' p2 + scale_y_continuous(labels = scales::dollar)
#' p2 + scale_x_continuous(labels = scales::comma)
#' p2 + scale_y_continuous(labels = scales::label_percent())
#' p2 + scale_y_continuous(labels = scales::label_dollar())
#' p2 + scale_x_continuous(labels = scales::label_comma())
#'
#' # You can also override the default linear mapping by using a
#' # transformation. There are three shortcuts:
Expand Down
4 changes: 2 additions & 2 deletions R/scale-date.R
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ datetime_scale <- function(aesthetics, trans, palette,
}
if (!is.waive(date_labels)) {
labels <- function(self, x) {
tz <- if (is.null(self$timezone)) "UTC" else self$timezone
date_format(date_labels, tz)(x)
tz <- self$timezone %||% "UTC"
label_date(date_labels, tz)(x)
}
}

Expand Down
2 changes: 1 addition & 1 deletion R/stat-binhex.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ StatBinhex <- ggproto("StatBinhex", Stat,

compute_group = function(data, scales, binwidth = NULL, bins = 30,
na.rm = FALSE) {
check_installed("hexbin", reason = "for `stat_bin_hex()`")
check_installed("hexbin", reason = "for `stat_bin_hex()`.")

binwidth <- binwidth %||% hex_binwidth(bins, scales)
wt <- data$weight %||% rep(1L, nrow(data))
Expand Down
2 changes: 1 addition & 1 deletion R/stat-quantilemethods.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ StatQuantile <- ggproto("StatQuantile", Stat,
compute_group = function(data, scales, quantiles = c(0.25, 0.5, 0.75),
formula = NULL, xseq = NULL, method = "rq",
method.args = list(), lambda = 1, na.rm = FALSE) {
check_installed("quantreg", reason = "for `stat_quantile()`")
check_installed("quantreg", reason = "for `stat_quantile()`.")

if (is.null(formula)) {
if (method == "rqss") {
Expand Down
2 changes: 1 addition & 1 deletion R/stat-summary-hex.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ StatSummaryHex <- ggproto("StatSummaryHex", Stat,

compute_group = function(data, scales, binwidth = NULL, bins = 30, drop = TRUE,
fun = "mean", fun.args = list()) {
check_installed("hexbin", reason = "for `stat_summary_hex()`")
check_installed("hexbin", reason = "for `stat_summary_hex()`.")

binwidth <- binwidth %||% hex_binwidth(bins, scales)
fun <- as_function(fun)
Expand Down
4 changes: 2 additions & 2 deletions man/annotation_logticks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/scale_continuous.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/sec_axis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-guides.R
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ test_that("guide_axis() draws minor ticks correctly", {
axis.minor.ticks.length.x.top = unit(-0.5, "cm"),
axis.minor.ticks.length.x.bottom = unit(0.75, "cm"),
axis.minor.ticks.length.y.right = unit(5, "cm")) +
scale_x_continuous(labels = math_format()) +
scale_x_continuous(labels = label_math()) +
guides(
# Test for styling and style inheritance
x = guide_axis(minor.ticks = TRUE),
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-scale_date.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ test_that("date scale draws correctly", {
expect_doppelganger("scale_x_date(breaks = \"3 weeks\")",
dt + scale_x_date(date_breaks = "3 weeks")
)
expect_doppelganger("scale_x_date(labels = date_format(\"%m/%d\"))",
dt + scale_x_date(labels = date_format("%m/%d"))
expect_doppelganger("scale_x_date(labels = label_date(\"%m/%d\"))",
dt + scale_x_date(labels = label_date("%m/%d"))
)
expect_doppelganger("scale_x_date(labels = date_format(\"%W\"), \"week\")",
dt + scale_x_date(labels = date_format("%W"), "week")
expect_doppelganger("scale_x_date(labels = label_date(\"%W\"), \"week\")",
dt + scale_x_date(labels = label_date("%W"), "week")
)

dt <- ggplot(df, aes(price, dx)) + geom_line()
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-scales-breaks-labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ test_that("minor breaks draw correctly", {
ggplot(df, aes(x_date, y)) +
geom_blank() +
scale_x_date(
labels = scales::date_format("%m/%d"),
labels = scales::label_date("%m/%d"),
breaks = scales::date_breaks("month"),
minor_breaks = scales::date_breaks("week")
) +
Expand Down