I'm creating two different x,y plots with ggplot2
. I want the scale of the y-axis to be the same (e.g. in both plots the distance between 0 and 10 is the same) but the length of each figure/plot to be different (if one plot goes to 20, and the other goes to 50, the the one that goes to 50 should be larger).
facet_Grid
isn't a great option as I have more than a hundred different plots to make.
Example data:
dat1 <- data.frame(replicate(2,sample(0:20,10,rep=TRUE)))
dat2 <- data.frame(replicate(2,sample(0:60,10,rep=TRUE))
Plot 1: y column data ranges from 0 to 20. x scale is 0 to 100
Plot 2: y column data ranges from 0 to 60. x scale is 0 to 100
Standard plot:
ggplot(data = dat1, aes (x=X1, y= X2)) + xlim(0,100)
ggplot(data = dat2, aes (x=X1, y= X2)) + xlim(0,100)
I get two plots of the same size, but the scale is different between them on the y-axis.
If I put limits on y to force them to be the same:
ggplot(data = dat1, aes (x=X1, y= X2)) + xlim(0,100) + ylim(0,60)
ggplot(data = dat2, aes (x=X1, y= X2)) + xlim(0,100) + ylim(0,60)
The first plot has a ton of wasted space between 20 and 60 that I don't want.
Any ideas of how to keep a consistent scale size in an output image, while having a different axis limit (thus different plot height in this case)? I need them to have the same scale on the printed page, but different heights.
Any ideas? Playing with scale_y_continuous
, coord_equal
, etc hasn't really managed to get me anywhere.
Example photoshopped mock-up of what I'm trying to make, but as separate output files. In each figure, 1cm on the y-axis would be the same between the multiple plots: