我用以下代码创建了一个森林图
虽然货币和空气质量方面/面板按我想要的顺序显示引文(根据因子水平),但元效应方面/面板没有。
我尝试移动两个 geom_point,发现只有第一个按因子顺序显示引文,第二个按字母顺序显示。我不确定这是为什么。以及如何在此图中获取两个图以按我想要的顺序显示引文。
## Data for the forest plot ##
forestdat= data.frame(matrix(NA,nrow=9))
# citations
forestdat$cite = c('Joshi & Fast (2013, Study 1)','Current Study 1', 'Tost et al. (2015, Study 2)',
'Joshi & Fast (2013, Study 3)','Current Study 2', 'Heller & Ullrich (2017)','Monetary','Air Quality','Overall' )
citeorder = c('Monetary','Heller & Ullrich (2017)','Air Quality','Overall','Joshi & Fast (2013, Study 1)','Current Study 1', 'Tost et al. (2015, Study 2)',
'Joshi & Fast (2013, Study 3)','Current Study 2')
citeorderforplot = citeorder[9:1]
forestdat$cite = ordered(forestdat$cite, levels = citeorderforplot )
# However I change the order of the three meta effect in cite, they always come out alphabetically
# the same for the connection graphs
# effect size
forestdat$effectsize = c(-0.3,-0.002,0.12,-0.17,-0.016,-0.04,-0.037,-0.066,-0.048)
# lowerci
forestdat$lowerci = c(-0.479,-0.067,-0.001,-0.321,-0.081,-0.128,-0.168,-0.192,-0.126)
# upperci
forestdat$upperci = c(-0.121,0.063,0.241,-0.019,0.049,0.048,0.095,0.06,0.031)
forestdat$weight = c(0.253,0.414,0.333,0.268,0.381,0.351,NA,NA,NA)
# subgroups settings
forestdat$subgroup = c('Monetary','Monetary','Monetary','Air Quality','Air Quality','Air Quality','Meta Effect','Meta Effect','Meta Effect')
forestdat$subgroup = ordered(forestdat$subgroup,levels=c('Monetary','Air Quality','Meta Effect'))
# Shape of point
forestdat$shapegroup = c('Individual','Individual','Individual','Individual','Individual','Individual','Summary','Summary','Summary')
## ggplot ## ggplot theme
apatheme=theme_bw()+
theme(panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
panel.border=element_blank(),
axis.line=element_line(),
legend.position='none')
library(ggplot2)
# forest plot ---------------------------------------------------------
p=ggplot(forestdat, aes(y=cite, x=effectsize, xmin=lowerci, xmax=upperci))+
#Add data points and color them black
geom_point(data=subset(forestdat,shapegroup != 'Summary'),color = 'black', shape = 15,
aes(size = weight))+
#Add 'special' points for the summary estimates, by making them diamond shaped
geom_point(data=subset(forestdat,shapegroup == 'Summary'), color='black', shape=18, size=4)+
#add the CI error bars
geom_errorbarh(height=.25)+
#Specify the limits of the x-axis and relabel it to something more meaningful
scale_x_continuous(limits=c(-0.6,0.3), name='Discount Rate Difference')+
#Give y-axis a meaningful label
#Add a vertical dashed line indicating an effect size of zero, for reference
geom_vline(xintercept=0, color='black', linetype='dashed')+
ylab("")+
#Create sub-plots (i.e., facets) based on levels of setting
#And allow them to have their own unique axes (so authors don't redundantly repeat)
#Apply my APA theme
facet_grid(subgroup~., scales= 'free', space='free')+
scale_size_area() +
apatheme
p