68
68
# ' # displayed bigger
69
69
# ' d + coord_cartesian(xlim = c(0, 1))
70
70
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 ) {
72
73
check_coord_limits(xlim )
73
74
check_coord_limits(ylim )
75
+ check_number_decimal(ratio , allow_infinite = FALSE , allow_null = TRUE )
74
76
ggproto(NULL , CoordCartesian ,
75
77
limits = list (x = xlim , y = ylim ),
76
78
reverse = reverse ,
77
79
expand = expand ,
78
80
default = default ,
79
- clip = clip
81
+ clip = clip ,
82
+ ratio = ratio
80
83
)
81
84
}
82
85
@@ -87,7 +90,13 @@ coord_cartesian <- function(xlim = NULL, ylim = NULL, expand = TRUE,
87
90
CoordCartesian <- ggproto(" CoordCartesian" , Coord ,
88
91
89
92
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
+ },
91
100
92
101
distance = function (x , y , panel_params ) {
93
102
max_dist <- dist_euclidean(panel_params $ x $ dimension(), panel_params $ y $ dimension())
0 commit comments