【发布时间】:2020-11-24 14:26:29
【问题描述】:
我正在尝试制作具有优势比以及上下 ci 的可发布图。现在我确实用 ggplot 得到了不错的图表,但我想在 geom_point-layer 上方添加显着性星,它们对应于三个级别(.005、.001、.001 )。我制作了一个示例数据框,从中获取我的值。它还包括 p 值:
or<-as.numeric(round(rnorm(5,0,1),2))
n<-c(100,100,100,100,100)
p<-c(.06,.05,.01,.0012,.000034)
df<-as.data.frame(cbind(or,n,p))
df$names<-as.factor(c(1:5))
df$lwr.ci<-as.numeric(or-2)
df$upr.ci<-as.numeric(or+2)
ggplot-code如下:
p <- ggplot(df, aes(or, fct_rev(names)))+
theme_bw(base_family = "Times New Roman")
p+geom_errorbarh(aes(xmax =upr.ci, xmin = lwr.ci), size = 1, height = 0, color = 'gray') +
geom_point(size = 2, color = 'black') +
theme(panel.grid = element_blank()) +
scale_x_continuous(breaks = c(0:13),limits = c(-4,5))+
ylab('CD') +
xlab('Odds Ratios')+
ggtitle('R')+
geom_text(parse=T,aes(label=paste(round(or,2),sep =" ","(","italic(n)==",n,")")),x= -3.5, size = 3,color='black',family="Times New Roman")
如果有人对如何将相应的重要性星添加到 geom_points 有任何建议,我将不胜感激。
【问题讨论】:
-
也许这个stackoverflow.com/questions/9723239/… 会有所帮助。