在R中的同一图中绘制两幅图 [英] Plot two graphs in same plot in R
本文介绍了在R中的同一图中绘制两幅图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
x < - seq(-2,2 ,0.05)
y1 < - pnorm(x)
y2 < - pnorm(x,1,1)
plot(x,y1,type =l,col =红色)
plot(x,y2,type =l,col =green)
但是,当我这样做时,它们不会一起绘制在同一个绘图中。
在Matlab中,可以执行 ,但是有人知道如何在R中执行此操作?
解决方案
lines()
或 points()
将添加到现有图形中,但不会创建新窗口。所以你需要做的是
$ p $ plot(x,y1,type =l,col =red)
lines(x,y2,col =green)
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.
In Matlab one can do hold on
, but does anyone know how to do this in R?
解决方案
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屋!
查看全文