You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the fixed-size elements in a plot sum to a dimension great than maxheight or maxwidth, get_dims reports the wrong dimensions, possibly including negative values that produce errors from graphical devices:
p= ggplot(mtcars, aes(wt,mpg))+theme_ggEHD(96)
get_dims(p, 1, 1)
# $height# [1] 1## $width# [1] -0.4104287
ggsave_fitmax("test.png", p, 1, 1) # calls get_dims under the hood# Error in grDevices::png(..., res = dpi, units = "in") : # invalid quartz() device size
get_dims(p, 5, 5)
# $height# [1] 5## $width# [1] 4.922905# ==> WRONG, this plot is supposed to be wider than it is tall!
ggsave_fitmax("test2.png", p, 5, 5)
# no error, but plot has wrong aspect ratio and is clipped with no warning
In this example, the reported width has no useful interpretation. The plot needs 6.50 inches of fixed height and 6.92 inches of fixed width, so get_dims subtracts those from 1 and divides the negative "remaining" space up between null units as min(1, 6.50 + ((1 - 6.92) * 0.75)) = 1 inches tall and min(1, 6.92 + ((1 - 6.50) / 0.75)) = -0.41 inches wide. Note especially that the "-0.41" cannot be interpreted as "the image needs to be at least 0.41 inches wider". It needs to be at least 5.92 inches wider just to start having room for the panel!
Probably best to fail loudly with something like
if(known_ht>=maxheight||known_wd>=maxwidth){
stop("This plot will not fit in an image smaller than",
deparse(known_ht), " x ", deparse(known_wd))}
Probably related to #9, in that both involve corner cases on image dimensions and ought to be considered at the same time.
The text was updated successfully, but these errors were encountered:
infotroph
changed the title
warn on negative get_dims output
get_dims gives wrong dimensions when fixed dims >= max
Mar 5, 2016
If the fixed-size elements in a plot sum to a dimension great than
maxheight
ormaxwidth
, get_dims reports the wrong dimensions, possibly including negative values that produce errors from graphical devices:In this example, the reported width has no useful interpretation. The plot needs 6.50 inches of fixed height and 6.92 inches of fixed width, so get_dims subtracts those from 1 and divides the negative "remaining" space up between null units as
min(1, 6.50 + ((1 - 6.92) * 0.75)) = 1
inches tall andmin(1, 6.92 + ((1 - 6.50) / 0.75)) = -0.41
inches wide. Note especially that the "-0.41" cannot be interpreted as "the image needs to be at least 0.41 inches wider". It needs to be at least 5.92 inches wider just to start having room for the panel!Probably best to fail loudly with something like
Probably related to #9, in that both involve corner cases on image dimensions and ought to be considered at the same time.
The text was updated successfully, but these errors were encountered: