【发布时间】:2016-07-31 10:46:49
【问题描述】:
我有一个时间序列数据文件,其中包含 4 种代谢物 A、B、AE 和 E 随时间变化的浓度。我有很多这种类型的数据文件(大约 100 个)。我想在一张图中绘制所有文件中所有四种代谢物的时间序列。每种代谢物都被分配了一种特定的颜色。
我编译了下面的代码,但是它只在一个文件(最后一个文件)中绘制数据。我认为这是因为当我调用 ggplot() 时,它会创建一个新的情节。我尝试在四个循环之外创建情节,但没有奏效。
p = NULL
for(i in 1:length(filesToProcess)){
fileName = filesToProcess[i]
fileContent = read.csv(fileName)
#fileContent$Time <- NULL
p <- ggplot()+
geom_line(data = fileContent, aes(x = Time, y = A, color = "A"), size =0.8) +
geom_line(data = fileContent, aes(x = Time, y = B, color = "B"), size =0.8) +
geom_line(data = fileContent, aes(x = Time, y = AE, color = "AE"), size =0.8) +
geom_line(data = fileContent, aes(x = Time, y = E, color = "E"), size =0.8) +
xlab('Time') +
ylab('Metabolite Concentration')+
ggtitle('Step Scan') +
labs(color="Metabolites")
}
plot(p)
可以找到示例文件 here
【问题讨论】: