随“时间”改变颜色的线图
我有一个数据框,其中包含以离散步骤(向上、向下、向左或向右 1 步)移动的随机游走的 x 和 y 坐标。我想绘制路径——由一条线连接的点。当然,这很容易。困难在于这条路径会自我交叉并且变得难以解释。我向点添加抖动以避免过度绘制,但这无助于区分行走的顺序。
我想使用一条线来连接这些点,该线根据类似温度计的色标随“时间”(步骤)改变颜色。
我的随机游走存储在它自己的类中,并且我正在为其编写一个特定的 plot
方法,因此,如果您对如何使用 plot
执行此操作有建议,那么会很棒的。谢谢!
I have a data frame that contains x and y coordinates for a random walk that moves in discrete steps (1 step up, down, left, or right). I'd like to plot the path---the points connected by a line. This is easy, of course. The difficulty is that the path crosses over itself and becomes difficult to interpret. I add jitter to the points to avoid overplotting, but it doesn't help distinguish the ordering of the walk.
I'd like to connect the points using a line that changes color over "time" (steps) according to a thermometer-like color scale.
My random walk is stored in its own class and I'm writing a specific plot
method for it, so if you have suggestions for how I can do this using plot
, that would be great. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这在 ggplot2 中很容易做到:
This is pretty easy to do in
ggplot2
:如果您不想使用 ggplot,那么
?segments
将执行您想要的操作。 -- 我在这里假设 x 和 y 都是时间的函数,正如您的示例中所暗示的那样。If you prefer not to use ggplot, then
?segments
will do what you want. -- I'm assuming here that x and y are both functions of time, as implied in your example.如果你使用ggplot,你可以设置颜色美感:
If you use ggplot, you can set the colour aesthetic: