According to this reference page on ggplot2, the following command should give an equal aspect ratio (1:1) of x and y.
qplot(mpg, wt, data = mtcars) + coord_equal(ratio = 1)
However, as I type it and I am seeing this.
Does anyone know what's the problem?
Edit:
Without +coord_equal()
however, I can obtain a 1:1 aspect ratio. However, as soon as I add legend on the right, the 1:1 aspect gets changed. The suggestions provided are simply too cumbersome to achieve desired effect. As suggested, I've filed a ticket to github/ggplot2.
Might as well turn my comment into an answer.
What your coord_equal(ratio = 1)
does is make sure that the an equal length on both axis represents the same change in units. So 1cm = 5units for both axis (for example - that conversion rate probably isn't correct but the idea is the same). Since the x axis is more variable it will be scrunched like that. You can add a ylim parameter to coord_equal
if you want the y-axis to be more stretched out.
After github/ggplot2 ticket filing. Winston helped me to find a succinct solution:
qplot(mpg,wt,data=mtcars, shape="carb") + theme(aspect.ratio=1)
Also, there appears to be some behavioral changes between ggplot2 0.8 to 0.9, the original documentation is probably out of date.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With