我想制作 2 个关于冒险和性别的散点图。我有 12 项研究,每项都有男性和女性的数据(均值、效应大小、抽样方差)。每项研究的平均值都非常不同,在一项研究中,男性为 1490,女性为 1200,在另一项研究中,男性为 33,女性为 25。我想在同一张图上制作 2 个不同的散点图。X 轴应该是年龄,Y 轴应该是冒险。我需要两条不同的曲线,一条用于女性,一条用于男性。我怎样才能融合这两条曲线?甚至有可能将所有内容都放在一张图表上吗?
我已经尝试过使用 ggplot2、geom_point() 和 metafor 包。
# yi = effect sizes of each study
# vi = sampling variance
# data = mydata
library("metafor")
# adjust margins so the space is better used
par(mar=c(5,5,1,2))
# fit mixed-effects model with age as predictor
res <- rma(yi, vi, mods = ~ magewomen, data=mydata)
# calculate predicted risk ratios for womens’ age 0-30.
preds <- predict(res, newmods=c(0:35), transf=exp)
# calculate point sizes by rescaling the standard errors
wi <- 1/sqrt(mydata$vi)
size <- 0.5 + 3.0 * (wi - min(wi))/(max(wi) - min(wi))
# plot the risk ratios against women’s age
women <- plot(mydata$magewomen, exp(mydata$yi), pch=19, cex=size,
xlab="womens age", ylab="Risk",
las=1, bty="l", log="y")
# add predicted values (and corresponding CI bounds)
lines(0:35, preds$pred)
lines(0:35, preds$ci.lb, lty="dashed")
lines(0:35, preds$ci.ub, lty="dashed")
# Same procedure, just for men
# adjust margins so the space is better used
par(mar=c(5,5,1,2))
# fit mixed-effects model with men’s age as predictor
res2 <- rma(yi, vi, mods = ~ magemen, data=mydata)
# calculate predicted risk ratios for men’s age from 0-30
preds2 <- predict(res2, newmods=c(0:35), transf=exp)
# calculate point sizes by rescaling the standard errors
wi <- 1/sqrt(mydata$vi)
size <- 0.5 + 3.0 * (wi - min(wi))/(max(wi) - min(wi))
# plot the risk ratios against men’s age
men <- plot(mydata$magemen, exp(mydata$yi), pch=19, cex=size,
xlab="mens age", ylab="Risk",
las=1, bty="l", log="y")
# add predicted values (and corresponding CI bounds)
lines(0:35, preds$pred)
lines(0:35, preds$ci.lb, lty="dashed")
lines(0:35, preds$ci.ub, lty="dashed")
我希望能够将我的 2 个散点图融合为一个,但我不知道如何。此外,这两个散点图看起来非常相似,我认为不应该如此。