I have 2 datasets, both with the column Depth. However df1 has ~400 rows and df2 7000 rows. The depth values, which I want to be my common x axis, for df1 go from 48-120 and df2 48-133. When I make my plots this difference in the range stops the plots from lining up.
df1 sample data
depth L F P Depo 67.48 1.003 1.063 1.066 Turb 67.63 1.004 1.020 1.024 Dri 67.73 1.011 1.017 1.028 Dri 67.83 1.006 1.007 1.014 Turb 67.92 1.003 1.029 1.032 Pro 68.06 1.004 1.007 1.011 Pro
df2 sample data
depth Ca Ti 67.41 378 241 67.91 422 253 67.94 402 262 67.95 412 264 67.98 377 266 68.01 386 263 68.02 326 266 68.08 338 219
I tried making individual plots and then using grid.draw but this doesn't work.
creating plots from DF1
Lin <- ggplot(DF1, aes(x=depth, y=L)) + geom_line() + geom_point(data = DF1, aes(x=depth, y=L, color = Depo))
Fab <- ggplot(DF1, aes(x=depth, y=P)) + geom_path() + geom_point(data = DF1, aes(x=depth, y=P, color = Depo))
Fol <- ggplot(DF1, aes(x=depth, y=F)) + geom_path() + geom_point(data = DF1, aes(x=depth, y=F, color = Depo))
Combining plots with grid.draw works for the df1 graphs
grid.draw(rbind(ggplotGrob(Fol), ggplotGrob(Lin), ggplotGrob(Fab), size = "last"))
Creating plot from DF2
Ca1 <- ggplot(DF2, aes(x=depth, y=Ca)) + geom_path()
When I try to combine the plots from the 2 dataframes it throws an error that x and y must have the same amount of columns.
grid.draw(rbind(ggplotGrob(Fol), ggplotGrob(Lin), ggplotGrob(Fab), ggplotGrob(Ca1), size = "last"))
Cowplot works but the depths don't line up for my df2 graph (Ca1)
plot_grid(Fol, Lin, Fab, Ca1, align="h", axis="b", nrow = 4, rel_widths = c(1,2))
I tried some other ways of lining the graphs up but it seems they all line the plots up, not the actual values of the x axis. I also tried to use facet wrap but couldn't work out how to combine the 2 dfs. In my searching to resolve this problem I keep seeing to combine the 2 dataframes but I can't see how this would work with my data? Does anyone know how I can line these graphs up? I have so many variables I need to compare from both datasets.