這是我關于錯誤欄主題的舊問題的擴展。假設這是我的測驗資料。
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。提前致謝。
uj5u.com熱心網友回復:
你可以試試
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")

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/527532.html
