使用 R 中的网格绘图系统制作可调整大小的图

发布于 2024-10-16 19:13:08 字数 143 浏览 9 评论 0原文

最近我读到了 R 中的网格绘图系统。它非常灵活,熟练掌握它应该能够制作非常复杂的图表。但是我还没有找到任何好地方可以让我绘制一个可以调整大小的图表?问题如下:如何在R中使用grid图形系统以使最终输出实际上可以调整大小?

Recently I read about the grid graphing system in R. It is very flexible and with its mastery one should be able to make very sophisticated graphs. However I have not found any good place that will allow me to plot a graph that is also re-sizable? The question is as follows: How do you use grid graphing system in R so that the final output is actually resizable?

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

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

发布评论

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

评论(1

人│生佛魔见 2024-10-23 19:13:08

一种方法是不直接使用夹点绘图系统,而是使用它的lattice接口。据我所知,lattice 包随 R 一起安装,并为底层的网格图(基于网格的图)形成了一个非常灵活的接口。 Lattice 还允许您直接操作网格,因此实际上对于最复杂的图形来说,这将是您所需要的。

如果您确实要使用网格绘图系统本身,则必须使用正确的坐标系才能使其可扩展。 “native”、“npc”(标准化父坐标)或“snpc”(方形标准化父坐标)都允许您重新缩放图形,因为它们给出相对于当前视口的大小(或其一个方面)的坐标。

为了充分利用这些,请确保您非常了解视口的概念。我必须承认我还有很多东西需要学习。如果你真的想继续下去,我可以推荐这本书 Paul Murrell 的 R Graphics

仔细阅读该书的第 5 章。您还可以从示例的 R 代码中学到很多东西,这些代码也可以在 此页面

给您一个:

grid.circle(x=seq(0.1, 0.9, length=100), 
            y=0.5 + 0.4*sin(seq(0, 2*pi, length=100)),
            r=abs(0.1*cos(seq(0, 2*pi, length=100))))

完美可扩展。如果您查看grid.circle的帮助页面,您会发现default.units="npc"选项。在本例中,这就是设置正确坐标系的位置。 比较。

grid.circle(x=seq(0.1, 0.9, length=100), 
            y=0.5 + 0.4*sin(seq(0, 2*pi, length=100)),
            r=abs(0.1*cos(seq(0, 2*pi, length=100))),
            default.units="inch")

与不可扩展的

One way of doing so is not using the grip graphing system directly, but use the lattice interface to it. The lattice package comes installed with R as far as I know, and forms a very flexible interface to the underlying Trellis graphs, which are grid-based graphs. Lattice also allows you to manipulate the grid directly, so in fact for most sophisticated graphs that will be all you need.

If you really are going to work with the grid graphing system itself, you have to use the correct coordinate system for it to be scalable. Either "native", "npc" (Normalized Parent Coordinates) or "snpc" (Square Normalized Parent Coordinates) allow you to rescale a figure, as they give the coordinates relative to the size (or one aspect of it) of the current viewport.

In order to make full use of these, make sure you understand the concept of viewports very well. I have to admit that I still have a lot to learn about it. If you really want to get on with it, I can suggest the book R Graphics from Paul Murrell

Take a closer look at chapter 5 of that book. You can also learn a lot from the R code of the examples, which can also be found on this page

To give you one :

grid.circle(x=seq(0.1, 0.9, length=100), 
            y=0.5 + 0.4*sin(seq(0, 2*pi, length=100)),
            r=abs(0.1*cos(seq(0, 2*pi, length=100))))

Perfectly scaleable. If you look at the help pages of grid.circle, you'll find the default.units="npc" option. That's where in this case the correct coordinate system is set. Compare to

grid.circle(x=seq(0.1, 0.9, length=100), 
            y=0.5 + 0.4*sin(seq(0, 2*pi, length=100)),
            r=abs(0.1*cos(seq(0, 2*pi, length=100))),
            default.units="inch")

which is not scaleable.

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