在 R 中绘制多组点
我有多组要绘制的 xy 对。我希望每组 xy 对都通过一条线连接。换句话说,目标是拥有多个实验实例,每个实例都用在一个图上绘制的线来近似。另外我如何给线条涂上不同的颜色?
绘图函数执行我想要的操作,但采用一组 xy 对: plot(x, y, ...)
这个函数可以接受多个集合吗?或者还有其他函数吗?
I have multiple sets of xy pairs that I want to plot. I want each set of xy pairs to be connected by a line. In other words the goal is to have multiple experimental instances each approximated by a line plotted on one plot. Also how would I colour the lines differently?
The plot function does what I want, but takes on one set of xy pairs:plot(x, y, ...)
Can this function be made to take multiple sets or is there another function for that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要使用普通绘图命令执行此操作,我通常会创建一个绘图,然后使用
lines()
函数添加更多行。否则你可以使用lattice或ggplot2。这里有一些数据:
您可以使用lattice中的
xyplot()
:或ggplot2中的
geom_line()
:这是另一个例子,包括每对的点(来自这篇文章在学习者博客上):
使用 ggplot2 绘制相同的图:
To do this with the normal plot command, I would usually create one plot and then add more lines using the
lines()
function.Otherwise you can use lattice or ggplot2. Here's some data:
You can use
xyplot()
from lattice:Or
geom_line()
in ggplot2:Here's another example including points at each pair (from this post on the learnr blog):
And the same plot using ggplot2: