【问题标题】:R annotate estimates with p < 0.05R 用 p < 0.05 注释估计值
【发布时间】:2022-11-02 15:01:00
【问题描述】:

这是我关于错误栏主题的旧问题的扩展。假设这是我的测试数据。

df1<-"Group      Est     conf.low      conf.high   pvalue   
       Bi         1.12    0.65          1.603       0.000
       Di        -0.24   -0.44         -0.038       0.02
       Dn        -0.47   -0.80         -0.140       0.005
       HMD       -0.006  -0.32          0.311       0.968
       HMS        -0.72   -1.00         -0.436       0.000
       LM        -0.055  -0.32          0.214       0.6886
       PaS       -1.31   -1.79         -0.850       0.000
       'Ph A'       0.065  -0.250         0.381       0.6885
       TRB        1.023   0.63          1.41        0.000
       TRC       -0.599  -0.94         -0.249       0.0008"
df1 <- read.table(textConnection(df1), header = TRUE)

下面的脚本将生成错误栏,没有任何问题。 图书馆(ggplot2)

ggplot(df1, aes(x = Est, y = reorder(Group, -Est))) +
  geom_pointrange(aes(xmin = conf.low, xmax = conf.high), size = 1) +
  geom_text(aes(label = Est), nudge_y = 0.3, size = 4) +
  geom_vline(xintercept = 1, linetype = "dashed", alpha = 0.5) +
  ylab("Group")

我的问题是如何在误差条上的估计值旁边添加 *,只有那些 p < 0.05

期待这样的剧情。

我可以使用annotate 函数手动执行此操作,但我对更自动化且无需添加多行annotation 的解决方案感兴趣。提前致谢。

【问题讨论】:

    标签: r ggplot2 p-value annotate


    【解决方案1】:

    你可以试试

    df2 <- df1 %>%
      filter(pvalue < 0.05) 
    ggplot(df1, aes(x = Est, y = reorder(Group, -Est))) +
      geom_pointrange(aes(xmin = conf.low, xmax = conf.high), size = 1) +
      geom_text(aes(label = Est), nudge_y = 0.3, size = 4) +
      geom_vline(xintercept = 1, linetype = "dashed", alpha = 0.5) +
      ylab("Group") +
      geom_text(data = df2, aes(x = Est, y = reorder(Group, -Est), label = "*"), size = 5, nudge_y = .3, nudge_x = .2, color = "red")
    

    【讨论】:

    • 完美我会测试的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-28
    • 2017-12-20
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    • 2014-06-23
    • 2016-08-03
    相关资源
    最近更新 更多