Я хочу построить функцию R для следующего фрагмента кода, который отображает график.Создание функции в R
ERO1B <- plotCounts(dds, gene="ERO1B", intgroup="treat", transform=TRUE, returnData=TRUE)
ERO1B$gene="ERO1B"
SLC4A10 <- plotCounts(dds, gene="SLC4A10", intgroup="treat", transform=TRUE, returnData=TRUE)
SLC4A10$gene="SLC4A10"
ggplot(rbind(ERO1B,SLC4A10), aes(x=factor(treat), y=count))+geom_boxplot(aes(fill=gene))+facet_wrap(~gene, scales="free")
Если мне нужно добавить еще один элемент, я сейчас делаю,
ERO1B <- plotCounts(dds, gene="ERO1B", intgroup="treat", transform=TRUE, returnData=TRUE)
ERO1B$gene="ERO1B"
SLC4A10 <- plotCounts(dds, gene="SLC4A10", intgroup="treat", transform=TRUE, returnData=TRUE)
SLC4A10$gene="SLC4A10"
G6PC2 <- plotCounts(dds, gene="G6PC2", intgroup="treat", transform=TRUE, returnData=TRUE)
G6PC2$gene="G6PC2"
ggplot(rbind(ERO1B,SLC4A10,G6PC2), aes(x=factor(treat), y=count))+geom_boxplot(aes(fill=gene))+facet_wrap(~gene, scales="free")
Я хотел бы иметь функцию, которая принимает вектор (любой длины) c("ERO1B","SLC4A10","G6PC2")
и итерацию, хотя вектор и участки:
plotGeneCounts <- function (dds, genes) {
for (i in 1:length(genes)) {
i <- plotCounts(dds, gene=genes[i], intgroup="treat", transform=TRUE, returnData=TRUE)
i$gene=genes[i]
gene_vec <- c("")
gene_vec <- gene_vec+i
}
ggplot(rbind(gene_vec), aes(x=factor(treat), y=count))+geom_boxplot(aes(fill=gene))+facet_wrap(~gene, scales="free")
}