在 R 中的同一图中绘制两个图 [英] Plot two graphs in same plot in R
本文介绍了在 R 中的同一图中绘制两个图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在同一个图中绘制 y1 和 y2.
I would like to plot y1 and y2 in the same plot.
x <- seq(-2, 2, 0.05)
y1 <- pnorm(x)
y2 <- pnorm(x, 1, 1)
plot(x, y1, type = "l", col = "red")
plot(x, y2, type = "l", col = "green")
但是当我这样做时,它们不会一起绘制在同一个图中.
But when I do it like this, they are not plotted in the same plot together.
在 Matlab 中可以做 hold on
,但有没有人知道如何在 R 中做到这一点?
In Matlab one can do hold on
, but does anyone know how to do this in R?
推荐答案
lines()
或 points()
将添加到现有图形,但不会创建新窗户.所以你需要做
lines()
or points()
will add to the existing graph, but will not create a new window. So you'd need to do
plot(x,y1,type="l",col="red")
lines(x,y2,col="green")
这篇关于在 R 中的同一图中绘制两个图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文