if I make a graph g
:
如果我做一个图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)
and matrix of coordinates:
和坐标矩阵:
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))
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.
但是xaxis限制功能不正常,我认为是由yaxis限制改变的。我怎样才能以他想要的方式控制x轴,例如将它保持在0和1之间。
i.e. 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?
这是一个错误吗?如果是,并且这无法解决是否有另一个具有相同功能的包?
1 个解决方案
#1
18
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.
简短的回答是,您需要将绘图调用的asp参数设置为0,因为默认值为asp = 1,这会产生您看到的行为(即,它不是错误,它是一个功能)。下面是解释的长答案。
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
:
正如您所注意到的那样,xaxis根据yaxis而有所不同。具体来说,x轴在高位数和低位数之间的距离大致与y轴相同:
- If
yaxis = c(0,6)
, the x-axis goes from -3 to 4.6 - 0 = 6
and4 - (-3) = 7
- If
yaxis = c(0,3)
, the x-axis goes from -1 to 2.3 - 0 = 2 - (-1) = 3
如果y轴= c(0,6),则x轴从-3变为4. 6 - 0 = 6和4 - ( - 3)= 7
如果yaxis = c(0,3),则x轴从-1变为2. 3 - 0 = 2 - ( - 1)= 3
Igraph seems to keep a constant ratio between the axes.
Igraph似乎在轴之间保持恒定的比例。
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
:
如果你调用?plot.igraph(用igraph对象调用的绘图函数,也可以通过help(package =“igraph”)找到),你可以在See Also下找到:
igraph.plotting
for the detailed description of the plotting parametersigraph.plotting用于绘图参数的详细描述
And if you click on this link (or call ?igraph.plotting
)and go through the parameters you will find:
如果您点击此链接(或致电?igraph.plotting)并查看参数,您会发现:
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.asp一个数字常量,它给出了绘图的asp参数,纵横比。如果您不想提供宽高比,请在此处提供0。它被tkplot和rglplot忽略。
Defaults to 1.
默认为1。
Hence the aspect parameter asp
defaults to 1
in igraph. If you want another ratio, set it to 0
:
因此,在igraph中,aspect参数asp默认为1。如果您想要另一个比率,请将其设置为0:
plot(g,layout=l,rescale=F,axes=TRUE,ylim=c(0,6),xlim=c(0,1), asp = 0)
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):
这回答了你的问题。但请注意,这些要点现在相当大。您可能想要使用以下参数(在?igraph.plotting上找到但请注意,许多参数需要以顶点作为前缀。如我所做的那样):
-
vertex.size
Default is 15, 5 seems better -
vertex.label.cex
Default is 1, 0.8 seems better.
vertex.size默认值为15,5似乎更好
vertex.label.cex默认值为1,0.8似乎更好。
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)
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)
#1
18
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.
简短的回答是,您需要将绘图调用的asp参数设置为0,因为默认值为asp = 1,这会产生您看到的行为(即,它不是错误,它是一个功能)。下面是解释的长答案。
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
:
正如您所注意到的那样,xaxis根据yaxis而有所不同。具体来说,x轴在高位数和低位数之间的距离大致与y轴相同:
- If
yaxis = c(0,6)
, the x-axis goes from -3 to 4.6 - 0 = 6
and4 - (-3) = 7
- If
yaxis = c(0,3)
, the x-axis goes from -1 to 2.3 - 0 = 2 - (-1) = 3
如果y轴= c(0,6),则x轴从-3变为4. 6 - 0 = 6和4 - ( - 3)= 7
如果yaxis = c(0,3),则x轴从-1变为2. 3 - 0 = 2 - ( - 1)= 3
Igraph seems to keep a constant ratio between the axes.
Igraph似乎在轴之间保持恒定的比例。
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
:
如果你调用?plot.igraph(用igraph对象调用的绘图函数,也可以通过help(package =“igraph”)找到),你可以在See Also下找到:
igraph.plotting
for the detailed description of the plotting parametersigraph.plotting用于绘图参数的详细描述
And if you click on this link (or call ?igraph.plotting
)and go through the parameters you will find:
如果您点击此链接(或致电?igraph.plotting)并查看参数,您会发现:
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.asp一个数字常量,它给出了绘图的asp参数,纵横比。如果您不想提供宽高比,请在此处提供0。它被tkplot和rglplot忽略。
Defaults to 1.
默认为1。
Hence the aspect parameter asp
defaults to 1
in igraph. If you want another ratio, set it to 0
:
因此,在igraph中,aspect参数asp默认为1。如果您想要另一个比率,请将其设置为0:
plot(g,layout=l,rescale=F,axes=TRUE,ylim=c(0,6),xlim=c(0,1), asp = 0)
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):
这回答了你的问题。但请注意,这些要点现在相当大。您可能想要使用以下参数(在?igraph.plotting上找到但请注意,许多参数需要以顶点作为前缀。如我所做的那样):
-
vertex.size
Default is 15, 5 seems better -
vertex.label.cex
Default is 1, 0.8 seems better.
vertex.size默认值为15,5似乎更好
vertex.label.cex默认值为1,0.8似乎更好。
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)
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)