【发布时间】:2015-09-17 12:32:36
【问题描述】:
我有一个数据框 df,看起来像这样
a b c d
row1 1 2 2 3
row2 2 4 5 9
row3 1 4 4 6
对于每一行,我想将直方图写入 pdf 中的页面。我试着这样做
for (i in 1:nrow(df)){
histogram <- ggplot(data=df, aes(x=as.numeric(df[i,]))) +geom_histogram()
ggsave(filename="output.pdf", plot=histogram)
}
但是,这给了我错误arguments imply differing number of rows: 115, 734。从这个答案:https://stackoverflow.com/a/26148043/651779我试着做
df$id <- rownames(df)
df <- melt(df)
for (i in 1:nrow(df)){
histogram <- ggplot(data=df, aes(x=as.numeric(df[i,]))) +geom_histogram()
ggsave(filename="output.pdf", plot=histogram)
}
但这给了我同样的错误,但号码不同arguments imply differing number of rows: 3, 84410
【问题讨论】: