tags:

views:

89

answers:

2

Hi, I have a data set like this one below:

DataFrame <- data.frame(x=runif(25),y=runif(25),
                        z=sample(letters[1:4],25,rep=TRUE))

and using the Lattice package, I can make a scatter plot with equal axes (with a 1:1 line going through the centre) with the following lines:

xyplot(y ~ x | z, data=DataFrame,
       scales=list(relation="free"),
       prepanel=function(x,y,...) {
         rg <- range(na.omit(c(x,y)))
         list(xlim=rg,ylim=rg)
       },panel=function(x,y,...) {
         panel.abline(0,1)
         panel.xyplot(x,y,...)
       })

In ggplot2, I have gotten this far:

ggplot(data=DataFrame) + geom_point(aes(x=x,y=y)) +
  facet_grid(~z,scales="free") + coord_equal(ratio=1) +
  geom_abline(intercept=0,slope=1)

But I'm not sure that coord_equal() is the function I'm looking for. What might be the equivalent function call in ggplot2?

+1  A: 

maybe facet_wrap() is a better choice, and afaik the control of xlim and ylim for individual panels is not available in ggplot2

__name__
+2  A: 

Your problem lies in setting free facet scales. Once you set the facet scales to be free, you can't then add coord_equal() If you eliminate the free scales, then coord_equal() works properly.

JoFrhwld
Thanks - but I want my scales free...
Stephen