-1
我想爲以下代碼片段構建一個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")
}