【问题标题】:plot each column of a dataframe on the same line graph in r在 r 中的同一折线图上绘制数据框的每一列
【发布时间】:2014-11-24 23:15:32
【问题描述】:

我有一个数据框,想在 R 中的同一折线图上按列绘制值(聚合残差)。数据框有 1000 列和 323 行。

我发现如何使用 ggplot 一次完成一个系列,但我无法弄清楚如何绘制所有这些系列而不必一次完成一个。有人有什么想法吗?

数据是这样的

http://imgur.com/Ry2eixO

(我没有发布图片的声誉)

【问题讨论】:

  • 您想在一张图上绘制 1000 条线?!此外,Stackoverflow 上肯定有数百个关于线图的问题。我觉得你没有很努力地搜索。
  • 你可以使用matplot(),也可以使用reshape2::melt(),然后使用ggplot()

标签: r plot model ggplot2


【解决方案1】:

这应该让你开始:假设你的 data.frame 被称为 df:

library(reshape2)
library(ggplot2)
D=melt(df, id='id')
ggplot(D,aes(id,value, group=variable, color=variable))+geom_line()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 2020-10-28
    • 2019-11-18
    • 2021-07-25
    相关资源
    最近更新 更多