Summary:
coord_equal() does not make the coordinate systems have an equal aspect ratio when using facet_wrap() in the cases where it is the horizontal axis which must be extended to make the coordinates equal. coord_equal() will affect the coordinate systems for vertically stretched axes when using facet_wrap(), and in all case when using facet_grid().
Reproducible code:
p_horiz_stretch <- ggplot(mtcars) +
geom_point(aes(x=5*hp, y=disp)) +
geom_abline() +
coord_equal()
p_vert_stretch <- ggplot(mtcars) +
geom_point(aes(x=hp, y=5*disp)) +
geom_abline() +
coord_equal()
p_horiz_stretch
p_horiz_stretch + facet_grid(am~.)
p_horiz_stretch + facet_grid(~am)
p_horiz_stretch + facet_wrap(~am)
p_vert_stretch
p_vert_stretch + facet_grid(am~.)
p_vert_stretch + facet_grid(~am)
p_vert_stretch + facet_wrap(~am)
Expected results:
facet_grid(~am) and facet_wrap(~am) should give the same figure (at least with respect to coordinate aspect ratios).
Actual results:
For p_horiz_stretch, facet_grid(~am) maintains the aspect ratio while facet_wrap(~am) does not. It appears, rather, to make the plot area square, not make the aspect ratio 1. That is, it has an effect (plot is different than if coord_equal() was left out completely), but not the right one. For p_vert_stretch, both maintain the aspect ratio.
Discussion:
p_horiz_stretch is a plot (using mtcars) where the x-axis has to be stretched (or the y-axis has to be contracted, depending on how you look at it) to make the coordinate systems equal. In addition to the points, a line with slope 1 is also drawn to make it easier to identify if the coordinates are in fact equal. Faceting, via facet_grid(), in either direction, maintains the appropriate ratio. However, wrapping, which for the two values of am should be the same as the immediately previous call with facet_grid, does not preserve the aspect ratio. By way of comparison, p_vert_stretch is a plot where the y-axis has be stretched (x-axis has to be contracted) which behaves as expected in all four scenarios.
Session Info:
R version 2.12.1 (2010-12-16)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_0.8.8 proto_0.3-8 reshape_0.8.3 plyr_1.2.1
Summary:
coord_equal() does not make the coordinate systems have an equal aspect ratio when using facet_wrap() in the cases where it is the horizontal axis which must be extended to make the coordinates equal. coord_equal() will affect the coordinate systems for vertically stretched axes when using facet_wrap(), and in all case when using facet_grid().
Reproducible code:
Expected results:
facet_grid(~am) and facet_wrap(~am) should give the same figure (at least with respect to coordinate aspect ratios).
Actual results:
For p_horiz_stretch, facet_grid(~am) maintains the aspect ratio while facet_wrap(~am) does not. It appears, rather, to make the plot area square, not make the aspect ratio 1. That is, it has an effect (plot is different than if coord_equal() was left out completely), but not the right one. For p_vert_stretch, both maintain the aspect ratio.
Discussion:
p_horiz_stretch is a plot (using mtcars) where the x-axis has to be stretched (or the y-axis has to be contracted, depending on how you look at it) to make the coordinate systems equal. In addition to the points, a line with slope 1 is also drawn to make it easier to identify if the coordinates are in fact equal. Faceting, via facet_grid(), in either direction, maintains the appropriate ratio. However, wrapping, which for the two values of am should be the same as the immediately previous call with facet_grid, does not preserve the aspect ratio. By way of comparison, p_vert_stretch is a plot where the y-axis has be stretched (x-axis has to be contracted) which behaves as expected in all four scenarios.
Session Info: