【问题标题】:Plotting titles and legends on interactive igraph plot? (R)在交互式 igraph 图上绘制标题和图例? (右)
【发布时间】:2018-05-29 22:39:17
【问题描述】:

我无法在图表内部添加标题和图例。 tkplot OR plot 不可能吗?

    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')

它似乎不想按我想要的方式工作。我只是想让图例显示调整为更大度数的顶点。

我还想知道是否有一种方法可以仅绘制图中的某些顶点?例如,您选择一个顶点并仅绘制形成返回它的路径的顶点?

【问题讨论】:

    标签: r plot legend igraph tkplot


    【解决方案1】:

    根据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"))
    

    对于标准基础 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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-14
      • 2016-05-08
      • 2012-02-26
      • 1970-01-01
      • 2021-04-08
      • 2016-01-18
      • 2015-12-15
      • 1970-01-01
      相关资源
      最近更新 更多