This is some data I made. I have two data frames with two variables each.
var1 <- (1:10)*(rnorm(10,2,0.1))
var2 <- (6:15)*(rnorm(10,1,0.1))
df1 <- as.data.frame(cbind(var1,var2))
var3 <- (1:10)*(rnorm(10,3,0.1))
var4 <- (6:15)*(rnorm(10,1.5,0.1))
df2 <- as.data.frame(cbind(var3,var4))
There is a loop for plotting the first variable of df1 and df2, and the second of df1 and df2 too.
plot_list = list()
for(i in 1:ncol(df1)){
p=ggplot(df1,
aes_string(x=df1[,i],
y=df2[,i]))+
geom_point()
plot_list[[i]] = p
}
library(gridExtra)
do.call("grid.arrange", c(plot_list[c(1:2)], ncol=1))
And this is the plot I got.
So far so good. But, I would like to x and y within each plot had the same limit based on max and min. For example, in the above plot both x and should go from ~5 to ~30. In the below plot both x and should go from ~6 to ~24. I could set the limits manually, but I need to do this for many plots.
Is there any way to set the x and y limits for each plot based on min and max observed in any of the axis?
Thanks for the help.