二分網絡igraph中的頂點屬性 (Vertex attributes in bipartite network igraph)


問題描述

二分網絡igraph中的頂點屬性 (Vertex attributes in bipartite network igraph)

我真正想做的是根據“人物遊戲”字段對人物頂點進行不同的著色,但這似乎不是我可以訪問頂點的屬性,只能訪問邊緣。所以這可以為邊緣著色:</p>

df <‑ read.csv("file.csv", header = TRUE, sep = ",")
df.network <‑ graph.data.frame(df, directed = F)
V(df.network)$type <‑ bipartite.mapping(df.network)$type

但是如果我應用到頂點而不是邊緣,它就不起作用,因為我無法將 PersonGame 屬性應用到頂點。

誰能幫忙?

任何人都可以幫忙嗎?</p> 任何人都可以幫忙嗎?</p>


參考解法

方法 1:

I recommend transferring the games to the nodes. Since some nodes are Groups and others are Persons, I will just call it Game (rather than PersonGame and GroupGame), but I will transfer the PersonGames to the Persons and the GroupGames to the Groups.

PA = unique(cbind(ends(df.network, E(df.network))[,2], E(df.network)$PersonGame))
GA = unique(cbind(ends(df.network, E(df.network))[,1], E(df.network)$GroupGame))

V(df.network)$Game = ""
V(df.network)[PA[,1]]$Game = PA[,2]
V(df.network)[GA[,1]]$Game = GA[,2]

Now, every node has a Game. We can modify your statement that created an edge color to create a vertex color. I added a line to color the Groups differently

V(df.network)$color <‑ ifelse(V(df.network)$Game=='Snooker', 
 "red", ifelse(V(df.network)$Game=='Football', "blue", "orange"))
V(df.network)[!V(df.network)$type]$color = "lightgray"

Now we can plot with node colors.

LO = layout_as_bipartite(df.network)
plot(df.network, layout=LO)

Network with colored nodes

(by otter77G5W)

參考文件

  1. Vertex attributes in bipartite network igraph (CC BY‑SA 2.5/3.0/4.0)

#R #bipartite #igraph #attributes






相關問題

如何將均值、標準差等函數應用於整個矩陣 (How to apply mean, sd etc. function to a whole matrix)

Tạo các thùng của mỗi hàng trong bảng và vẽ hình thanh ngăn xếp trong R (Make bins of each table row and draw stack bar figure in R)

Reading not quite correct .csv file in R (Reading not quite correct .csv file in R)

包'treemap'中的線條粗細 (Thickness of lines in Package ‘treemap’)

是否需要帶有 awk 的預處理文件,或者可以直接在 R 中完成? (Is preprocessing file with awk needed or it can be done directly in R?)

rpivotTable 選擇元素下拉菜單 (rpivotTable select elements drop down menu)

優化性能 - Shiny 中的大文件輸入 (Optimizing Performance - Large File Input in Shiny)

數值取決於所應用的應用系列,R (Numeric values depending of apply family applied, R)

如何記錄全年的值? (How to note the values across year?)

R中的線性搜索 (Linear search in R)

在 dplyr/purrr 工作流程中動態連接多個數據集 (Dynamically join multiple datasets in a dplyr/purrr workflow)

如何將行值更改為列名 (R) (How change Row values to Column names (R))







留言討論