I can force ggplot2 scatter plot to be square shaped with the same x and y scaling using xlim()
and ylim()
, but it needs manual calculation of the limits. Is there any more convenient way of doing it?
By square shape I mean two requirements:
- The same scale on x and y axis.
- The equal length of x and y axis.
x
direction to be the same as in they
direction (meaning ifx
goes from 0 to 5 andy
goes from 0 to 6 they
dimension will be one unit longer), or do you mean that you want the length of the entire x axis to be the same as the y axis (so in the previous example, each unit ofy
is shorter than each unit ofx
but the entire graph looks square)?asp=1
in base plotting.theme(aspect.ratio=1)
expand_limits
, but I believe one way or another you'll have to compute min and max of your data manually.