首页 > 解决方案 > 如何在 R 中的 lapply 中输入变量作为图表的 ggtitle 的一部分?

问题描述

我有一个 lapply 函数,它将我的绘图函数应用于 qList 列表中的每个元素(每个元素都是一个数据表)。每个元素也已经是疾病的名称。

volcanoList <- lapply(unique(qList),
                  function(x) volcanoGraph(x))

火山图函数是以下标准 ggplot 函数:

volcanoGraph <- function(dataSetOrdered) {
ggplot(dataSetOrdered) +
    geom_point(aes(x=MeanDiff, y=-log10(qColumn), colour=threshold)) +
    geom_text_repel(aes(x = MeanDiff, y = -log10(qColumn), label= 
    ifelse(geneLabels %in% 1:10 == T | minDiff %in% 1:10 == T | maxDiff %in% 
    1:10 == T, geneMutCount,""))) +
    xlab("WT - Mutation Mean Difference") + 
    ylab("-log10 adjusted q-value") +
    #scale_y_continuous(limits = c(0,50)) +
    theme(legend.position = "none",
          plot.title = element_text(size = rel(1.5), hjust = 0.5),
          axis.title = element_text(size = rel(1.25)))
}

截至目前,它没有附加 ggtitle,因为我不知道如何根据每个元素对应的疾病(基于元素名称)为每个元素制作标题。作为预期的输出,我想为每个图标记标题:“图(在此处插入元素名称)”。

标签: r

解决方案


推荐阅读