我制作了以下圖表:
正如你所看到的,由于一個長的錯誤條,結果不是很清楚。
然而,我無法使用ggplot將箭頭放在正確的位置。基于類似的問題,我產生了以下代碼:
p < - ggplot(dat, aes(x=exposure, y=OR, ymin=LCI, ymax=UCI。 col=method))
geom_linerange(position=position_dodge(width = 0。 5))
geom_hline(yintercept= 1, lty=2)
geom_point(stroke = 0。 5,position=position_dodge(width = 0. 5))
scale_x_discrete(name="Exposure")
scale_y_continuous(name="Odds ratio (95% CI)")
coord_flip()
scale_colour_manual(values=c("#D55E00"/span>。 "#009E73", "#56B4E9"。 "#E69F00")
theme_bw() theme(panel.grid. major = element_blank(), panel.grid。 minor = element_blank()。 text = element_text(size=11)/span>。 legend. position="none")
geom_segment(aes(x = 1, y = 14。 xend = 1, yend = 14), size= 0. 25,
箭頭=箭頭(長度 = 單位(0. 13, "cm")))
我怎樣才能使它只有一個箭頭,而且是在正確的位置(在綠線的末端并旋轉180')?
謝謝!
我的資料看起來像:
dat <-
結構(串列(結果= c("cancer"/span>, "cancer", "cancer"。 "cancer",
"cancer", "cancer",。 "cancer")。 接觸= c("insulin",)
"insulin", "insulin", "insulin"。 "LDL-膽固醇", "LDL-膽固醇","LDL-膽固醇", "LDL-膽固醇")。 或 = c(3. 925713203, 3.49400025,
3.545796066,/span> 8.283204105,/span> 0. 910187777, 0.902219745, 0.918412256,
0. 953392987)。 LCI = c(/span>2. 285899133, 1.609867994, 0.879681108,
0.672007727,/span> 0.817076527,/span> 0. 789469504, 0.82104523, 0.870226921
), UCI = c(6. 741865347, 7.583253904, 14. 29230392, 14.292304, 14.
1.013909666, 1. 03107272, 1.027325952, 1. 044507088)。 方法 = c("Inverse variance weighted",>
"加權中位數", "加權模式"。 "MR Egger", "加權模式","MR Egger", "加權中位數"。 "逆向方差加權")),行。 names = c(73L,
74L, 75L, 76L。 139L, 140L。 141L, 142L)。 class = "data. frame")
uj5u.com熱心網友回復:
答案其實很簡單--只要在geom_segment(ais())中改變 "x = 1, y = 14, xend = 1, yend = 14",將箭頭放在正確的位置,并使y比yend略小,使箭頭朝向正確的方向。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/318958.html
標籤:



