[R] ggplot2, coord_equal and aspect ratio

jiho jo.irisson at gmail.com
Fri Jan 11 01:16:25 CET 2008


Hi everyone, Hi Hadley,

I am a heavy user of coord_equal() in ggplot2 since most of my data is  
spatial, on x,y coordinates. Everything works. However by enforcing an  
aspect ratio of 1 for the plotting region, coord_equal() usually  
wastes a lot of space if the region of interest is not a perfect square.

For example:
	x=runif(10)
	a=data.frame(x=x*3,y=x)
	ggplot(data=a, aes(x=x,y=y)) + geom_point() + coord_equal()
produces a square plotting region while all the data is constrained in  
an horizontally extended rectangle. I would expect the coordinates to  
stay equal but the plot to be extended so that it fills as much as the  
plotting region as possible. It does not appear to be currently  
doable. Is it a limitation of ggplot? of the underlying grids  
graphics? Is there a workaround this?

Thanks in advance for your help.

PS:
	x=runif(10)
	qplot(x*3, x) + coord_equal()
produces some very strange scales. this looks like a bug to me.  
especially since:
	foo=x
	qplot(foo*3, foo) + coord_equal()
works as expected

PPS: I tried
	ggplot(data=a, aes(x=x,y=y)) + geom_point() + coord_equal() +  
scale_y_continuous(limits=c(0,1))
which has no effect. but the side effect of enforcing the square  
domain is that:
	ggplot(data=a, aes(x=x,y=y)) + geom_point() + coord_equal() +  
scale_y_continuous(limits=c(0,0.3))
has no effect either (i would expect to see only the points <0.3)

JiHO
---
http://jo.irisson.free.fr/




More information about the R-help mailing list