R中的折线图比较2列中的值

时间:2013-09-25 16:17:46

标签: r linegraph

我在数据框中有两列

>head(obs_v_exp)
    observed expected
    1          3.5
    6          8.9

如何在R中绘制线图,在一个图形中显示观察到的和预期的2条线? 谢谢!

2 个答案:

答案 0 :(得分:4)

试试这个

plot(obs_v_exp$observed, type="l")
lines(obs_v_exp$expected, col="red")

以下是一个例子:

set.seed(2)
obs_v_exp <- data.frame(observed=sample(0:6, 10, TRUE),
                        expected=sample(0:6, 10, TRUE))
plot(obs_v_exp$observed, type="l")
lines(obs_v_exp$expected, col="red")

enter image description here

答案 1 :(得分:1)

查看matplot函数:

matplot(obs_v_exp, type='l')
相关问题