igraph轴xlim ylim图错误 [英] igraph axes xlim ylim plot incorrectly

查看:125
本文介绍了igraph轴xlim ylim图错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我制作图形g:

g <- read.table(text="

 A  B   W

 1  55  3
 2  55  5
 3  99  6 ",header=TRUE)

library(igraph)
g <- graph.data.frame(g)

和坐标矩阵:

y<-1:5
x<-c(0.1,0.1,0.2,0.2,0.8)
l<-data.frame(x,y)
l<-as.matrix(l)

我可以根据自定义坐标和坐标轴绘制带有节点位置的图形.

I can plot the graph with node positions according to custom coordinates and plot axes.

plot(g,layout=l,rescale=F,axes=TRUE,ylim=c(0,6),xlim=c(0,1))

但是xaxis限制无法正常运行,我认为会受到yaxis限制的影响.如何以自己希望的方式控制xaxis,例如将其保持在0到1之间.

But the xaxis limits do not function properly and I think are altered by yaxis limits. How can I control the xaxis they way i want for instance keeping it between 0 and 1.

plot(x,y,xlim=c(0,1),ylim=c(0,6))

这是一个错误吗?如果是这样并且无法解决,那么是否还有另一个具有相同功能的软件包?

Is this a bug? If it is and this cannot be solved is there another package that would have the same functionality?

推荐答案

最简单的答案是,您需要将要绘制的调用的asp参数设置为0,因为默认值为asp = 1,这会产生您看到的行为(即不是错误,而是功能).详细的解释如下.

The short answer is, you need to set the asp argument of the call to plot to 0 as the default is asp = 1 which produces the behavior you see (i.e., it's not a bug, it's a feature). The long answer with explanation follows.

正如您正确注意到的那样,xaxis根据yaxis的不同而不同.具体来说,x轴的高低数字之间的距离与yaxis大致相同:

As you noticed correctly, xaxis varies according to yaxis. Specifically, the x-axis has approxamitely the same distance between high and low numbers as yaxis:

  • 如果yaxis = c(0,6),则x轴从-3变为4.6 - 0 = 64 - (-3) = 7
  • 如果yaxis = c(0,3),则x轴从-1变为2.3 - 0 = 2 - (-1) = 3
  • If yaxis = c(0,6), the x-axis goes from -3 to 4. 6 - 0 = 6 and 4 - (-3) = 7
  • If yaxis = c(0,3), the x-axis goes from -1 to 2. 3 - 0 = 2 - (-1) = 3

Igraph似乎在轴之间保持恒定的比例.

Igraph seems to keep a constant ratio between the axes.

如果调用?plot.igraph(使用igraph对象调用的绘图功能,也可以通过help(package = "igraph")找到),则可以在See Also下找到:

If you call ?plot.igraph (the plotting function called with an igraph object, can also be found via help(package = "igraph")), you find under See Also:

igraph.plotting有关绘图的详细说明 参数

igraph.plotting for the detailed description of the plotting parameters

如果您单击此链接(或调用?igraph.plotting)并浏览参数,则会发现:

And if you click on this link (or call ?igraph.plotting)and go through the parameters you will find:

asp一个数字常数,它给出用于绘图的asp参数(长宽比).如果您不想给出宽高比,请在此处提供0.
它会被tkplot和rglplot忽略.

asp A numeric constant, it gives the asp parameter for plot, the aspect ratio. Supply 0 here if you don't want to give an aspect ratio.
It is ignored by tkplot and rglplot.

默认为1.

因此,宽高比参数asp在igraph中默认为1.如果您想要其他比率,请将其设置为0:

Hence the aspect parameter asp defaults to 1 in igraph. If you want another ratio, set it to 0:

plot(g,layout=l,rescale=F,axes=TRUE,ylim=c(0,6),xlim=c(0,1), asp = 0)

这回答了您的问题.但是,请注意,现在的要点很大.您可能想使用以下参数(在?igraph.plotting上找到,但请注意,许多参数都需要像我一样以vertex.为前缀):

This answers your question. However, note that the points are now rather big. You will probably want to play around with the following parameters (found on ?igraph.plotting but note that many of the parameters need to be prefixed by vertex. as done by me):

  • vertex.size默认值为15,5似乎更好
  • vertex.label.cex默认值为1,0.8似乎更好.
  • vertex.size Default is 15, 5 seems better
  • vertex.label.cex Default is 1, 0.8 seems better.

以下内容可以绘制出更好的图:

The following produces a nicer plot:

plot(g,layout=l,rescale=F,axes=TRUE,ylim=c(0,6),xlim=c(0,1), asp = 0, vertex.size = 5, vertex.label.cex = 0.8)

这篇关于igraph轴xlim ylim图错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆