Skip to content

Commit

Permalink
sf_rescale01_x <- scales::rescale (#5475)
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Oct 30, 2023
1 parent 42a764d commit c4a337a
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions R/coord-sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
# transform and normalize regular position data
data <- transform_position(
sf_transform_xy(data, target_crs, source_crs),
function(x) sf_rescale01_x(x, panel_params$x_range),
function(x) sf_rescale01_x(x, panel_params$y_range)
function(x) rescale(x, from = panel_params$x_range),
function(x) rescale(x, from = panel_params$y_range)
)

transform_position(data, squish_infinite, squish_infinite)
Expand Down Expand Up @@ -250,10 +250,10 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,

# Rescale graticule for panel grid
sf::st_geometry(graticule) <- sf_rescale01(sf::st_geometry(graticule), x_range, y_range)
graticule$x_start <- sf_rescale01_x(graticule$x_start, x_range)
graticule$x_end <- sf_rescale01_x(graticule$x_end, x_range)
graticule$y_start <- sf_rescale01_x(graticule$y_start, y_range)
graticule$y_end <- sf_rescale01_x(graticule$y_end, y_range)
graticule$x_start <- rescale(graticule$x_start, from = x_range)
graticule$x_end <- rescale(graticule$x_end, from = x_range)
graticule$y_start <- rescale(graticule$y_start, from = y_range)
graticule$y_end <- rescale(graticule$y_end, from = y_range)

list2(
x_range = x_range,
Expand Down Expand Up @@ -405,11 +405,6 @@ sf_rescale01 <- function(x, x_range, y_range) {
sf::st_normalize(x, c(x_range[1], y_range[1], x_range[2], y_range[2]))
}

# normalize position data (variable x is x or y position)
sf_rescale01_x <- function(x, range) {
(x - range[1]) / diff(range)
}

# different limits methods
calc_limits_bbox <- function(method, xlim, ylim, crs, default_crs) {
if (any(!is.finite(c(xlim, ylim))) && method != "geometry_bbox") {
Expand Down

0 comments on commit c4a337a

Please sign in to comment.