I am trying to generate a set of plots with log-scaled axes and the same coordinates on both axes, as well as a square aspect ratio. Let's consider the following hypothetical data:
set.seed(1)
x <- rnorm(30, 50, 20)
y <- x + 20 + rnorm(30, 0, 10)
By using the code below, I obtain a rectangular plot:
p <- qplot(x, y) +
scale_x_continuous(trans = "log2") +
scale_y_continuous(trans = "log2") +
coord_equal()
Now if I try to force the aspect ratio to 1:1 with the theme()
function, it breaks the equal coordinate system:
p + theme(aspect.ratio = 1)
Is there a way to get both the equal scaling and the square aspect ratio that does not imply to manually change the limits for each graph? I would need to apply the same code to a whole series of data with different values and thus different limits.