我创建了一个循环来制作57个箱形图,使用grep
来挑选我想要的变量。但是,无论出于何种原因,Y轴始终标记为它抓取的第一个变量,尽管它抓取所有57个唯一变量并创建循环。我想知道是否有人可以看看它,看看我如何让Y轴与数据实际对应。以下是我的代码。
labely = names(ivf_dataset)[grep("_DMR_", names(ivf_dataset), ignore.case = T, fixed = TRUE)] #grabbing first only why?
myboxplot <- function(mydata=ivf_dataset, myexposure, myoutcome ) {
bp <- ggplot(mydata, aes(x = as.factor(get(myexposure)), y =
get(myoutcome))) +
geom_boxplot()
print(bp)
}
# test one variable
myboxplot(myexposure = "ART_CURRENT", myoutcome = "H19_DMR_mean")
# creating loop for 57 boxplots
outcomes = names(ivf_dataset)[grep("_DMR_", names(ivf_dataset), ignore.case = T)] #pulls out dmr names
allplots <- list()
for (i in seq_along(outcomes)) {
allplots[[i]]<- myboxplot (myexposure = "ART_CURRENT", myoutcome =
outcomes[i])$plot + xlab("ART_CURRENT") +
ylab(labely)
}
allplots