Free scale, but same per-panel range in x/y

Viewed 1155

I try to get free scaling with aspect=1, but same range in x/y in each panel. In the example below, this means that x-scaling in b should be (-0.04,0.04).

Edited: added lattice version

library(ggplot2)
d = data.frame(x=rnorm(100),group=c("A","B"))
d$y = d$x+rnorm(100,0,0.5)
d[d$group=="B","x"]=d[d$group=="B","x"]/100
d[d$group=="B","y"]=d[d$group=="B","y"]/60
qplot(x,y,data=d,asp=1) + facet_wrap(~group,scale="free")

require(lattice)
xyplot(y~x|group, data=d,aspect=1,scales=list(relation="free"),
   prepanel=function(x,y){
     lims = c(min(x,y), max(x,y))
     list(xlim=lims,ylim=lims)
   } )

in each panel, the x and y range should be the same

1 Answers
Related