跨多个地块连接线 R 地质横截面

Join lines across multiple plots R geological cross section

我正在尝试重新创建一个类似于下图的地质横截面,它显示了根据深度(y 轴)绘制的各种岩石参数(x 轴)

我可以很好地重新创建 ggplot2 和网格中的各个图,以创建非常相似的东西。最后,我真的很想在显示与图片中类似地质区域的地块之间加入线条。

下面是一些用水平线绘制图表的代码,我真正要做的是连接线(如果可能的话在 R 中)并尽可能根据线对齐图表

library(ggplot2)
library(gridExtra)

df1 = data.frame(replicate(2,sample(0:200,100,rep=TRUE)))
df1$depth = seq.int(nrow(df1))

df2 = data.frame(replicate(2,sample(0:200,100,rep=TRUE)))
df2$depth = seq.int(nrow(df1))


top1 = 32
top2 = 50

plot1 = ggplot(df1, aes(y = depth, x = X1))+
  scale_y_continuous(trans = "reverse")+
  geom_path()+
  geom_hline(yintercept=top1, colour = "red")+
  annotate(geom="text", x=25, y=top1, label=top1, color="red")+
  theme_bw()+
  theme(panel.grid.major = element_line(colour = "grey"), panel.background = element_rect(colour = "black", size=0.5))+
  ylab("Depth ft")+
  ggtitle("plot1")


plot2 = ggplot(df2, aes(y = depth, x = X1))+
  scale_y_continuous(trans = "reverse")+
  geom_path()+
  geom_hline(yintercept=top2, colour = "red")+
  annotate(geom="text", x=25, y=top2, label=top2, color="red")+
  theme_bw()+
  theme(panel.grid.major = element_line(colour = "grey"), panel.background = element_rect(colour = "black", size=0.5))+
  ylab("Depth ft")+
  ggtitle("plot2")

grid.arrange (plot1, plot2, ncol=2)

这将是我希望通过连接并尽可能对齐的线条寻找的结果。

感谢您提供的任何帮助或建议

干杯

line-joining 部分我帮不上忙,但移位音阶的想法听起来很有趣。该解决方案采用任意数量的数据帧和随附的等值线列表,然后移动 y-scale 以便每个等值线都为 0。

然后绘制每个数据帧,并适当地重新编号 y-axes。

library(purrr)
library(dplyr)
library(ggplot2)

# library(cowplot)
#   I never load `cowplot` because it changes some settings onload.
#   I just call the namespace with `cowplot::plot_grid(...)`
#   You will need it installed though.

depth_plots <- function(..., isolines) {
  dats <- list(...)
  stopifnot(length(dats) == length(isolines))

  scaled_dats <- map2(dats, isolines, ~.x %>% mutate(sc_depth = depth - .y))

  new_range <- 
    map(scaled_dats, ~range(.x$sc_depth)) %>% 
    unlist() %>% 
    range() %>% 
    scales::expand_range(mul = 0.05)

  plots <- map2(
    scaled_dats, isolines,
    ~ggplot(.x, aes(y = sc_depth, x = X1)) +
      scale_y_continuous(
        trans = "reverse", 
        breaks = scales::extended_breaks()(.x$depth) - .y,
        labels = scales::extended_breaks()(.x$depth)
        ) +
      geom_path() +
      geom_hline(yintercept=0, colour = "red") +
      annotate(geom="text", x=25, y=0, label=.y, color="red") +
      coord_cartesian(
        ylim = new_range
      ) +
      theme_bw()
  ) 

  cowplot::plot_grid(plotlist = plots, nrow = 1)
}

为了测试不同的深度结构,我稍微更改了您的示例数据:

df1 = data.frame(replicate(2,sample(0:200,100,rep=TRUE)))
df1$depth = seq.int(nrow(df1))

df2 = data.frame(replicate(2,sample(0:200,100,rep=TRUE)))
df2$depth = seq.int(nrow(df1))*0.75

df3 = data.frame(replicate(2,sample(0:200,100,rep=TRUE)))
df3$depth = seq.int(nrow(df1))*2

depth_plots(df1, df2, df3, isolines = c(32,50, 4))

希望能帮助您入门!