Take the 2-minute tour ×

How can I use R to make axes always square in scatter plots? for example in:

> plot(iris)


> 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)


enter image description here

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.

share|improve this question
What is a square axis? –  joran Feb 1 '13 at 23:00
Unless the square axes and the log scale are the same thing, not two different things...? I can't quite tell. –  joran Feb 1 '13 at 23:06
That code works perfectly for me. I suspect the issue you have is because you're plotting to a device window that's already open. When I run that line with no plotting devices open, a new one is created that is perfectly square. Also, it's good to double check with a device written to disk (i.e. png()) since resizing the device window can cause so much to change. –  joran Feb 2 '13 at 1:23
add comment

2 Answers

up vote 5 down vote accepted

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

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


share|improve this answer
Nice visual verification. +1 –  Ananda Mahto Feb 2 '13 at 9:11
add comment

First of all, for me the plot already comes out square (big image). Clearly for you this is not the case, and you might need to make plots larger than the screen anyhow.

So, the size of the plot is controlled by the size of the output area, ie the plot window, the image file, or whatever else. Using Rstudio, you can use the built-in GUI the specify plot size. If you insist on using the base R console, you'll need to manually do the exporting. First open the file:

png("image.png", width=600, height=600)

This will open an image file in the working directory with equal proportions. Now plot:

x = iris$Petal.Width
y = iris$Petal.Length
all = c(x,y)
range = c(min(all), max(all))
plot(x, y, xlim=range, ylim=range)

And close the file:


The result:

enter image description here

share|improve this answer
This is not a square axis -- it uses the same ticks, but the dimensions are not square. The x-axis is longer than the y –  user248237dfsf Feb 1 '13 at 23:30
@user248237 Ah, so maybe my request for clarification wasn't so stupid after all. Maybe you're referring to the aspect ratio...? –  joran Feb 1 '13 at 23:31
@joran: sure, I think it's also pretty standardly called square axes. In matlab, the command is axis(square) –  user248237dfsf Feb 1 '13 at 23:36
@user248237 The plot is automatically resized to the window or the size of the exported image. I use Rstudio which has a GUI for giving pixel size of the result. For using the R console, see stackoverflow.com/questions/6227020/… (use the same number for width and height if you want a square plot) –  Superbest Feb 1 '13 at 23:36
@user248237 Well, "square axes" is new to me. I've always heard it referred to as aspect ratio. Try passing asp = 1 in your plot call and see if that's closer to what you want. –  joran Feb 1 '13 at 23:39
show 3 more comments

Your Answer


