@@ -711,20 +711,28 @@ gg2list <- function(p, width = NULL, height = NULL,
711
711
)
712
712
713
713
# set scaleanchor/scaleratio if these are fixed coordinates
714
+ # the logic here is similar to what p$coordinates$aspect() does,
715
+ # but the ratio is scaled to the data range by plotly.js
714
716
fixed_coords <- c(" CoordSf" , " CoordFixed" , " CoordMap" , " CoordQuickmap" )
715
717
if (inherits(p $ coordinates , fixed_coords )) {
716
718
axisObj $ scaleanchor <- anchor
717
719
ratio <- p $ coordinates $ ratio %|| % 1
718
- # a la CoordSf$aspect
720
+ axisObj $ scaleratio <- if (xy == " y" ) ratio else 1 / ratio
721
+
719
722
if (inherits(p $ coordinates , " CoordSf" )) {
720
723
if (isTRUE(sf :: st_is_longlat(rng $ crs ))) {
721
724
ratio <- cos(mean(rng $ y_range ) * pi / 180 )
722
725
}
726
+ # note how ratio is flipped in CoordSf$aspect() vs CoordFixed$aspect()
727
+ axisObj $ scaleratio <- if (xy == " y" ) 1 / ratio else ratio
723
728
}
724
- axisObj $ scaleratio <- if (xy == " y" ) ratio else 1 / ratio
725
729
}
726
730
727
- # TODO: should we implement aspect ratios?
731
+ # TODO: seems like we _could_ support this with scaleanchors,
732
+ # but inverse transform by the panel ranges?
733
+ # also, note how aspect.ratio overwrites fixed coordinates:
734
+ # ggplot(mtcars, aes(wt, mpg)) + geom_point() + coord_fixed(0.5)
735
+ # ggplot(mtcars, aes(wt, mpg)) + geom_point() + coord_fixed(0.5) + theme(aspect.ratio = 1)
728
736
if (! is.null(theme $ aspect.ratio )) {
729
737
warning(
730
738
" Aspect ratios aren't yet implemented, but you can manually set" ,
0 commit comments