在交互式igraph情节上绘制标题和传说? (R)

时间:2017-12-15 17:22:40

标签: r plot legend igraph tkplot

我在向图表内部添加标题和图例时遇到问题。 tkplot OR情节不可能吗?

    dff <- data.frame(a = c(0,1,2,3,4),b = c(3,4,5,6,7))
    nod <- data.frame(node = c(0:7),wt = c(1:8))
    pg <- graph_from_data_frame(d = dff, vertices = nod,directed = F)

    # plot function with edge.label added
    tkplot(pg, edge.label = nod$wt, main = "this is my graph")
    legend('topleft',legend= degree(pg)*5,pt.cex=20,col='white',
    pch=21, pt.bg='white')

它似乎不想以我想要的方式工作。我只想让图例显示调整到更高程度的顶点。

我还想知道是否有一种方法只能从图中绘制某些顶点?例如,您选择一个顶点并仅绘制形成路径的顶点吗?

1 个答案:

答案 0 :(得分:0)

根据tkplot的帮助,以下是如何为交互式地块添加标题的示例:

library(tcltk)

id = tkplot(pg, edge.label = nod$wt, main = "this is my graph")
canvas = tk_canvas(id)

width = as.numeric(tkcget(canvas, "-width"))
height = as.numeric(tkcget(canvas, "-height"))
tkcreate(canvas, "text", width/2, 25, text="My title",
         justify="center", 
         font=tkfont.create(family="helvetica", size=20, weight="bold"))

enter image description here

对于标准基础R图,您的代码按原样运行:

plot(pg, edge.label = nod$wt, main = "this is my graph")
legend('topleft',legend= degree(pg)*5,pt.cex=20,col='white',
       pch=21, pt.bg='white')

enter image description here