I have a problem with re-arrangement of labels when making a forestplot with GGplot 2. Hope someone can help! The problem:
I have made the plot using the following code:
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")
It gives this output: https://i.stack.imgur.com/X65kO.png
Labels are arranged in this order:
- Time spent in PACU, min
- Remifentanil infusionrate, µg/kg/hour
- Propofol infusionsrate, mg/kg/hour
- BIS
I need to arrange the labels in this order:
- Remifentanil infusionrate, µg/kg/hour
- Propofol infusionsrate, mg/kg/hour
- BIS
- Time spent in PACU, min
Does anyone know how to do that? Thank you in advance!