用ggplot重现井日志图?

标签 r ggplot2

我有一组测井数据。在行业中,有专门的软件可以生成典型的钻孔测井图。这是一个简化的:
well-log plot

需要注意的令人兴奋的事情是:

  • 它们本质上是分面图
  • 深度是独立变量,但在垂直轴上
  • 绘制了几对测井日志,
  • 对联中的每个日志可能有不同的取值范围

  • 因为这是一个非常传统的行业,我想用我拥有的软件(我没有专业的东西,作为一名学生)密切复制这些绘图的格式。我已经使用 ggplot 沿着这条路走了一点路,但我不知道该怎么做。首先,这里有一些示例数据和代码:
    log <- structure(list(Depth = c(282.0924, 282.2448, 282.3972, 282.5496, 
    282.702, 282.8544, 283.0068, 283.1592, 283.3116, 283.464, 283.6164, 
    283.7688, 283.9212, 284.0736, 284.226, 284.3784, 284.5308, 284.6832, 
    284.8356, 284.988), FOO = c(4.0054, 4.0054, 4.0054, 4.0691, 4.0691, 
    4.0691, 4.0674, 4.0247, 4.0247, 4.0247, 4.0362, 4.1059, 4.2019, 
    4.2019, 4.2019, 4.0601, 4.0601, 4.0601, 4.2025, 4.387), BAR = c(192.126, 
    190.2222, 188.6759, 188.6759, 188.6759, 189.7761, 189.7761, 189.7761, 
    189.2443, 187.2355, 184.9368, 182.5421, 181.882, 181.344, 180.9305, 
    180.9305, 180.9305, 181.5986, 182.4397, 182.8301)), .Names = c("Depth", 
    "FOO", "BAR"), row.names = c(NA, 20L), class = "data.frame")
    
    library(reshape2)
    library(ggplot2)
    
    # Melt via Depth:
    melted <- melt(log, id.vars='Depth')
    
    sp <- ggplot(melted, aes(x=value, y=Depth)) +
        theme_bw() + 
        geom_path() + 
        labs(title='') +
        scale_y_reverse() + 
        facet_grid(. ~ variable, scales='free_x')
    

    我不知道如何:
  • 在一个方面结合两个变量,并成功管理范围
  • 具有如上图所示的值范围,位于构面的顶部
  • 将标签绘制为单独的方面。我已经从示例数据中排除了标签,因为它只是让我感到困惑。

  • 欢迎任何帮助。

    最佳答案

    I don't know how to:

    • combine two variables on one facet, and manage ranges successfully

    我的回答仅涉及您的第一个要点的第一部分。colsplit()函数对于此类情况很有用。假设多个孔的变量名称 仪器 就像 FOO_1 , FOO_2 , BAR_1 , BAR_2对于测量变量FOOBAR过井仪器 1 和 2,然后您可以调用 colsplitmelt 之后将适当的结构添加回融化的数据框。
    #your data, note changed field names
    log <- structure(list(Depth = c(282.0924, 282.2448, 282.3972, 282.5496, 
    282.702, 282.8544, 283.0068, 283.1592, 283.3116, 283.464, 283.6164, 
    283.7688, 283.9212, 284.0736, 284.226, 284.3784, 284.5308, 284.6832, 
    284.8356, 284.988), FOO = c(4.0054, 4.0054, 4.0054, 4.0691, 4.0691, 
    4.0691, 4.0674, 4.0247, 4.0247, 4.0247, 4.0362, 4.1059, 4.2019, 
    4.2019, 4.2019, 4.0601, 4.0601, 4.0601, 4.2025, 4.387), BAR = c(192.126, 
    190.2222, 188.6759, 188.6759, 188.6759, 189.7761, 189.7761, 189.7761, 
    189.2443, 187.2355, 184.9368, 182.5421, 181.882, 181.344, 180.9305, 
    180.9305, 180.9305, 181.5986, 182.4397, 182.8301)), .Names = c("Depth", 
    "FOO_1", "BAR_1"), row.names = c(NA, 20L), class = "data.frame")
    
    #adding toy data for 2nd well
    log$FOO_2 <- log$FOO_1 + rnorm(20, sd=0.1)
    log$BAR_2 <- log$BAR_1 + rnorm(20, sd=1)
    
    #melting
    melted <- melt(log, id.vars='Depth')
    
    #use of colsplit
    melted[, c('Var', 'Well')] <- colsplit(melted$variable, '_', c('Var', 'Well'))
    melted$Well <- as.factor(melted$Well)
    
    sp <- ggplot(melted, aes(x=value, y=Depth, color=Well)) +
        theme_bw() + 
        geom_path(aes(linetype=Well)) + 
        labs(title='') +
        scale_y_reverse() + 
        facet_grid(. ~ Var, scales='free_x')
    
    enter image description here

    关于用ggplot重现井日志图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21895903/

    相关文章:

    r - 文件 ../MatrixOps/cholmod_sdmult.c 第 90 行处出现 Cholmod 错误 'X and/or Y have wrong dimensions'

    r - 如何在 ggplot2 R 中绘制一条回归线,但按不同因素绘制颜色点?

    r - 在 ggplot2 中正确格式化两行标题

    r - 在 R 中使用 ggmap 添加上下文(或任意) map 插图?

    r - 在R中使用AUC包时出错

    r - 如何在 Shiny 的 navbarPage() 上将图像插入导航栏

    r - 将多个字段匹配(和求和)到 R 中的一个字段

    r - ggplot : adjusting alpha/fill two factors cdf

    r - 如何在ggplot中创建构面,除非使用不同的变量

    r - 计算数据集中因子水平的相对频率