【发布时间】:2022-01-21 01:04:42
【问题描述】:
在使用 ggplot 2 制作森林图时,我遇到了重新排列标签的问题。希望有人能提供帮助! 问题:
我使用以下代码制作了情节:
df <- data.frame(t(data.frame(
c("Remifentanil infusionrate, µg/kg/hour",3.1,-0.2,6.2,0.02),
c("Propofol infusionsrate, mg/kg/hour",0.3,-0.04,0.7,0.13),
c("BIS",-1.6,-6.5,5.3,0.72),
c("Time spent in PACU, min",0.2,-0.3,0.6,0.44))))
library(ggplot2)
ggplot(data=df, aes(x=X1,y=as.numeric(X2),
ymin=as.numeric(X3),ymax=as.numeric(X4),
label=X5)) +
geom_point() +
geom_linerange() +
ylab("Difference (95% Confidence Interval)") +
theme_minimal() +
coord_flip() +
theme(axis.title.y = element_blank()) +
geom_text(aes(y=Inf), hjust=1) +
ggtitle("Primary and Secondary Outcomes")
它给出了这个输出:
标签按以下顺序排列:
- 在 PACU 中花费的时间,分钟
- 瑞芬太尼输注速率,µg/kg/小时
- 丙泊酚输注速率,mg/kg/小时
- BIS
我需要按这个顺序排列标签:
- 瑞芬太尼输注速率,µg/kg/小时
- 丙泊酚输注速率,mg/kg/小时
- BIS
- 在 PACU 中花费的时间,分钟
有人知道怎么做吗?
【问题讨论】:
-
数据框似乎是一种非常规格式,这是设计使然吗?
-
这能回答你的问题吗? Order discrete x scale by frequency/value
标签: r ggplot2 forestplot