Skip to content

Commit

Permalink
Fix bin2d and hex scale treatment
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhodge931 committed Jun 30, 2023
1 parent 6950621 commit 7b6b7c4
Show file tree
Hide file tree
Showing 38 changed files with 82 additions and 73 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Breaking: made `col_rescale` require a function (e.g. `scales::rescale()`).
* Added `facet_switch` argument.
* Made `col_legend_place = "none"` only remove the col legend.
* Made `gg_bin2d` and `gg_hex` scales calculate in the same way as other functions.
* For raster, removed col aesthetic so that legend would work.
* Improved `gg_sf` default `alpha`.
* Supported `gg_sf` to work with non-standard named geometry.
Expand Down
4 changes: 2 additions & 2 deletions R/gg_area.R
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ gg_area <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -448,7 +448,7 @@ gg_area <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_bar.R
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ gg_bar <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -453,7 +453,7 @@ gg_bar <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
7 changes: 4 additions & 3 deletions R/gg_bin2d.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
#' gg_bin2d(
#' x = carat,
#' y = price,
#' pal = viridis::cividis(9)
#' pal = viridis::cividis(9),
#' y_limits = c(NA, 20000)
#' )
#'
gg_bin2d <- function(
Expand Down Expand Up @@ -439,7 +440,7 @@ gg_bin2d <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -474,7 +475,7 @@ gg_bin2d <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_blank.R
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ gg_blank <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -824,7 +824,7 @@ gg_blank <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ gg_boxplot <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -608,7 +608,7 @@ gg_boxplot <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_col.R
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ gg_col <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -460,7 +460,7 @@ gg_col <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_crossbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ gg_crossbar <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -542,7 +542,7 @@ gg_crossbar <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_density.R
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ gg_density <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -454,7 +454,7 @@ gg_density <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_errorbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ gg_errorbar <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -539,7 +539,7 @@ gg_errorbar <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_freqpoly.R
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ gg_freqpoly <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -461,7 +461,7 @@ gg_freqpoly <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
8 changes: 5 additions & 3 deletions R/gg_hex.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@
#' x = carat,
#' y = price,
#' pal = viridis::cividis(9),
#' coord = coord_cartesian(clip = "on"))
#' y_limits = c(NA, 20000),
#' coord = coord_cartesian(clip = "on")
#' )
#'
gg_hex <- function(
data = NULL,
Expand Down Expand Up @@ -442,7 +444,7 @@ gg_hex <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -477,7 +479,7 @@ gg_hex <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_histogram.R
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ gg_histogram <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -454,7 +454,7 @@ gg_histogram <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_jitter.R
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ gg_jitter <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -453,7 +453,7 @@ gg_jitter <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_label.R
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ gg_label <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -468,7 +468,7 @@ gg_label <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_line.R
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ gg_line <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -448,7 +448,7 @@ gg_line <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_linerange.R
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ gg_linerange <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -537,7 +537,7 @@ gg_linerange <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ gg_path <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -452,7 +452,7 @@ gg_path <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_point.R
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ gg_point <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -453,7 +453,7 @@ gg_point <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_pointrange.R
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ gg_pointrange <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -540,7 +540,7 @@ gg_pointrange <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
4 changes: 2 additions & 2 deletions R/gg_polygon.R
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ gg_polygon <- function(
#Get the positional scales right first
if (stat != "sf") {
if (rlang::is_null(x_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (x_numeric) x_limits <- c(NA, NA)
if (x_date | x_datetime | x_time) {
x_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down Expand Up @@ -478,7 +478,7 @@ gg_polygon <- function(
}

if (rlang::is_null(y_limits)) {
if (stat %in% c("bin", "bin2d", "bin_2d", "binhex")) {
if (stat == "bin") {
if (y_numeric) y_limits <- c(NA, NA)
if (y_date | y_datetime | y_time) {
y_limits <- c(lubridate::NA_Date_, lubridate::NA_Date_)
Expand Down
Loading

0 comments on commit 7b6b7c4

Please sign in to comment.