I have a dataset similar to the one below:
DataFrame <- data.frame(x=runif(25),y=runif(25),
z=sample(letters[1:4],25,rep=TRUE))
and using the lattice packet, I can make a scatter plot with equal axes (with a 1: 1 line through the center) 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 got 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 if the coord_equal () function is the function I'm looking for. What could be the equivalent function call in ggplot2?
source
share