I have two dataframes one for x and other for y values. I could use facet_grid
but I need to fix x and y limits for individual plots independently which I think is not possible in ggpubr
. Hence I tried to use ggplot2
in for loop. Heres my code
create list of names in data to loop over
grid.names <- names(X1)
p <- vector("list", ncol(X1))
# create for loop to produce ggplot2 graphs
for (i in seq_along(grid.names)) {
message(i)
#x and y limits for each grid
xy_min <- min(min(X1[[i]],X2[[i]])) - 100
xy_max <- max(max(X1[[i]],X2[[i]])) + 100
# create plot for each county in df
p[[i]] <- qplot(X1[[i]], X2[[i]]) + geom_point() +
coord_cartesian(xlim = c(xy_min, xy_max),
ylim = c(xy_min, xy_max))
geom_abline()
print(p[[i]])
rm(xy_max, xy_min)
#save plots as .png
#ggsave(plot, file=paste('L:/Workspace/Trend/pcp/Seasonal',
enter image description here # grid.names[i], ".png", sep=''), scale=2)enter code here
I get plots in the form of lists. But the problem is that all the plots are made of identical column, ie the last column of both dataframes. The xlim
and ylim
are Okay. Can someone help me figure out what's happening? I am adding sample data, but the original data has many more variables.