Skip to content

Commit 8266af7

Browse files
committed
incorporate coord_cartesian(ratio)
1 parent 295f5cb commit 8266af7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

R/coord-cartesian-.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,18 @@
6868
#' # displayed bigger
6969
#' d + coord_cartesian(xlim = c(0, 1))
7070
coord_cartesian <- function(xlim = NULL, ylim = NULL, expand = TRUE,
71-
default = FALSE, clip = "on", reverse = "none") {
71+
default = FALSE, clip = "on", reverse = "none",
72+
ratio = NULL) {
7273
check_coord_limits(xlim)
7374
check_coord_limits(ylim)
75+
check_number_decimal(ratio, allow_infinite = FALSE, allow_null = TRUE)
7476
ggproto(NULL, CoordCartesian,
7577
limits = list(x = xlim, y = ylim),
7678
reverse = reverse,
7779
expand = expand,
7880
default = default,
79-
clip = clip
81+
clip = clip,
82+
ratio = ratio
8083
)
8184
}
8285

@@ -87,7 +90,13 @@ coord_cartesian <- function(xlim = NULL, ylim = NULL, expand = TRUE,
8790
CoordCartesian <- ggproto("CoordCartesian", Coord,
8891

8992
is_linear = function() TRUE,
90-
is_free = function() TRUE,
93+
is_free = function(self) is.null(self$ratio),
94+
aspect = function(self, ranges) {
95+
if (is.null(self$ratio)) {
96+
return(NULL)
97+
}
98+
diff(ranges$y.range) / diff(ranges$x.range) * self$ratio
99+
},
91100

92101
distance = function(x, y, panel_params) {
93102
max_dist <- dist_euclidean(panel_params$x$dimension(), panel_params$y$dimension())

0 commit comments

Comments
 (0)