如果你想他们都在一个单一的情节,这将是最简单的,如果您首先“堆叠”数据框并包含一个列,用于标识数据来自哪个原始数据框。
library(dplyr)
library(ggplot2)
首先创建假数据。下面的代码创建一个包含八个数据帧的列表。我们假设这是我们读完数据后开始的地方。使用ggplot
# Fake data
set.seed(954)
df = lapply(paste0("d",0:7), function(x) {
n=sample(seq(100,500,100),1)
data.frame(source=x, index=1:n, values=cumsum(rnorm(n)))
})
# Stack the eight data frames into a single data frame
df = bind_rows(df)
简介:如果你从不同的文件中的数据帧(CSV文件,例如)读取,刚刚看了他们都到一个列表,然后使用bind_rows
堆栈他们。我们使用source
(原始数据帧的名称)作为colour
审美:
ggplot(df, aes(index, values, colour=source)) +
geom_line() +
theme_bw()
或者,如果你想正常化index
跨越每个数据帧相同的范围:
ggplot(df %>% group_by(source) %>%
mutate(index = index/max(index)),
aes(index, values, colour=source)) +
geom_line() +
theme_bw()
更新:在回答您的意见,如果你有数据帧已经,你可以这样做是为了得到一个数据帧:
df=lapply(paste0("sign",1:8), function(x) {
data.frame(source=x, get(x))
})
df=bind_rows(df)
但你必须在某个时候将数据读入R和你可以照顾当您将数据文件读入R时,此类处理就是这种类型的处理。
如果您可以提供可重现的示例http://stackoverflow.com/help/mcve,这非常有帮助。 –