【问题标题】:Plotting multiple lines from multiple data frames从多个数据帧中绘制多条线
【发布时间】:2013-02-07 01:50:52
【问题描述】:

我是 R 的初学者。所以我有 2 个数据文件,A.dat 和 B.dat,例如:

1   101203
2   3231233  
3   213213
...

原来如此

A <- read.table("A.dat", col.names = c("time","power"))
B <- read.table("B.dat", col.names = c("time","power"))

我想在同一个系统中为 A 和 B 做线图(对不起,我还不能上传图片)。关于如何进行的任何建议?

【问题讨论】:

    标签: r plot ggplot2 dataframe


    【解决方案1】:

    我更喜欢使用ggplot2(可以从 CRAN 下载包)。这首先需要一些数据处理:

    A$group = "A"
    B$group = "B"
    dat = rbind(A,B)
    

    然后绘制图形:

    ggplot(aes(x = time, y = power, color = group), data = dat) + geom_line()
    

    对于基本图形,这样的东西应该可以工作:

    plot(power~time, A)
    lines(power~time, B)
    

    【讨论】:

    • 只是好奇,你选择了情节解决方案吗。
    猜你喜欢
    • 1970-01-01
    • 2021-01-08
    • 1970-01-01
    • 2012-06-16
    • 2021-12-10
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    相关资源
    最近更新 更多