将图与轴归一化结合起来

发布于 2024-09-16 05:33:03 字数 144 浏览 1 评论 0原文

我在每个图之前使用 par(new=T) 将我的图添加到同一个图表中。

然而,当我这样做时,它会叠加两个图,并且轴值会相互覆盖并且看起来很混乱。

如何正确地将绘图添加到同一个图表中,该图表还根据两个绘图标准化轴间隔?

I use par(new=T) before each of my plots to add my plot to the same graph.

However, when I do that it superimposes the two plots and the axis values get overwritten over each other and look messed up.

How do I properly add plot to the same graph that also normalizes axis intervals based on the two plots?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遮云壑 2024-09-23 05:33:03

使用 par(new=TRUE) 应该作为最后的手段,通常有更好/更简单的方法。创建原始图时,设置 xlim 和 ylim 为要绘制的所有变量包含足够的空间,然后使用线、点、符号或其他函数来添加附加信息:例如:

plot(x1,y1, xlim=range(x1,x2,x3), ylim=range(y1,y2,y3))
points(x2,y2, col='blue')
points(x3,y3, col='red')

还有 matplot 函数可以在单个命令中绘制多条线或多组点。

更好的方法是将数据集组合在一起,然后使用lattice包或ggplot2包中的xyplot一步完成多个绘图。

plotrix 包中还有一些用于组合图形的函数(可以选择不同的比例)。

如果您确实需要使用 par(new=TRUE),则只需在每个绘图函数中指定 xlim 和 ylim 即可强制它们对齐。您还可以通过指定axes=FALSE或xaxt='n'、yaxt='n'来抑制默认轴的绘制,然后,如果需要,您可以使用axis函数在另一侧放置轴并可以指定正是您想要刻度线和标签的地方。

Use of par(new=TRUE) should be saved as a very last resort, usually there is a better/easier way. When creating the original plot set the xlim and ylim to include enough space for all the variables you will be plotting, then us functions like lines, points, symbols, or others to add the additional information: e.g.:

plot(x1,y1, xlim=range(x1,x2,x3), ylim=range(y1,y2,y3))
points(x2,y2, col='blue')
points(x3,y3, col='red')

There is also the matplot function which can plot several lines or sets of points in a single command.

Even better is to combine the data sets together then use xyplot from the lattice package or the ggplot2 package to do the multiple plots in one step.

There are also some functions in the plotrix package for combining graphs (with different scales as an option).

If you really need to use par(new=TRUE), then just specify the xlim and ylim in every plotting function to force them to line up. You can also supress the plotting of the default axes by specifying axes=FALSE or xaxt='n', yaxt='n', then, if wanted, you can use the axis function to put in axes on the other sides and can specify exactly where you want tick marks and labels.

夢归不見 2024-09-23 05:33:03

尝试 ?lines?points?abline?plot.xy

Try ?lines, ?points, ?abline, or ?plot.xy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文