Making square axes in R

graphics, plot, r

Solution

You need to also set `pty="s"` in the graphics parameters to make the plot region square (independent of device size and limits):

par(pty="s")
plot(iris$Petal.Width, iris$Petal.Length, asp=1)
lines(2+c(0,1,1,0,0),3+c(0,0,1,1,0)) # confirm square visually

Problem

How can I use R to make axes always square in scatter plots? for example in: ``` > plot(iris) ``` or ``` > plot(iris$Petal.Width, iris$Petal.Length) ``` I'd like the axes to be square, i.e. the same length and tick labels for the x and y axes. The current proposed answer does not work: the call, ``` plot(iris$Petal.Width, iris$Petal.Length, xlim=c(0,10), ylim=c(0,10), asp=1) ``` Generates: which is not square, and does not have the same axis ticks and tick labels. The spaces between the x tick labels must be the same and the plot should be square, not rectangular.

Original source

Related problems