我想根据已发布的摘要数据绘制危险比(hr)和置信区间,因为我在x轴上有相应的出版物,在y轴上有危险比。
目前,我的y轴显示为(-3,-2,-1、0、1、2、3),它给出了hr的“非对称”缩放。
我如何将y轴编程为(0.3、0.2、0.1、0、1、2、3),这将给出hr的“正确”缩放?
#require(plotrix)
#Create a data frame containing hr and confidence intervals
mean <- c(0.73, 0.7, 0.6, 0.74, 0.9, 0.96, 0.87, 0.74)
lowerlimit <- c(0.1, 0.4, 0.34, 0.29, 0.79, 0.86, 0.72, 0.57)
upperlimit <- c(5.55, 1.16, 0.99, 1.85, 1.03, 1.17, 1.04, 1.12)
df <- data.frame(cbind(upperlimit,lowerlimit, mean))
#Create a plot of the hr and CI for the respective publications
plot(df$mean, ylim = c(-3, 3), xlim = c(1,8), xaxt="n")
axis(1, at=seq(1:8), las=2,
labels=c("study1", "study2", "study3", "study4", "study5", "study6", "study7", "study8"))
plotCI(df$mean, y=NULL, uiw=df$upperlimit, liw=df$lowerlimit, err="y", pch=20, slty=3, scol = "blue", add=TRUE)
Ps。如果不可能修改间隔,则有一个中间步骤,(1/lowerlimit)
将给出正确的缩放比例,但给出“错误的数字”。然后可以证明对y轴进行硬编码是一种解决方案(尝试这种方法没有成功)。
答案 0 :(得分:1)
可能有几种方法可以做到这一点。这是我的ggplot
方法。您可以相应地打扮它。
您的数据
mean <- c(0.73, 0.7, 0.6, 0.74, 0.9, 0.96, 0.87, 0.74)
lowerlimit <- c(0.1, 0.4, 0.34, 0.29, 0.79, 0.86, 0.72, 0.57)
upperlimit <- c(5.55, 1.16, 0.99, 1.85, 1.03, 1.17, 1.04, 1.12)
study <- c(1:8)
df <- data.frame(cbind(upperlimit,lowerlimit, mean, study))
我的ggplot
方法:
library(ggplot2)
labels <- paste("Study", c(1:8))
df %>%
ggplot(aes(x = study, y= mean)) +
geom_point() +
geom_errorbar(aes(ymin = lowerlimit, ymax = upperlimit), width = 0.1) +
scale_y_log10() +
scale_x_continuous(breaks = c(1:8), labels = labels)