我想对 R 中的二分网络图中的顶点标签使用不同的字体。第一列是人名,第二列是该人所属的组织(可以有双重从属关系)。
这是数据示例
# R version 3.5.1 (2018-07-02) -- "Feather Spray"
# igraph 1.2.4
set.seed(7)
# bipartite network data
nodes <- read.csv("example.csv", header = TRUE, sep =";")
> nodes
Person Organisation
1 John SPD
2 Maria SPD
3 John CDU
4 Karl CDU
5 Maik Greens
6 Lisa Left
7 Holger SPD
8 Nico CDU
9 Peter Greens
10 Astrid SPD
11 Theo Left
12 Rita Greens
13 Eric FDP
14 Walter CDU
15 Hilda FDP
16 Boris CDU
17 Olga FDP
18 Nina Left
19 Doris CDU
20 Udo SPD
summary(nodes)
library(igraph)
# different fonts and node shapes
shape <- c("circle", "square")
let <- c("Times", "Helvetica")
# creating graph (g)
g <- graph.data.frame(nodes, directed = FALSE)
# creating bipartite network
V(g)$type <- FALSE
V(g)$type[V(g)$name %in% nodes[, 1]] <- TRUE
plot(g, layout= layout_with_kk,
vertex.shape= shape[as.numeric(V(g)$type) + 1],
vertex.label.family= let[as.numeric(V(g)$type)+1]
)
我为图中识别的数据分配了两种字体样式(没有特殊的字体样式)。但是,出现以下错误,我不知道如何解决:
In doTryCatch(return(expr), name, parentenv, handler) :
Zeichensatzfamilie in der Windows Zeichensatzdatenbank nicht gefunden (Translation: Font family is not found in the Windows font database)
我在这里找不到任何相关问题。
感谢您提前提供的帮助和建议!
最佳答案
如果我只是运行您的代码,我会收到类似的错误消息,但您可以通过在 plot
语句之前添加这些语句来解决此问题。
windowsFonts("Times" = windowsFont("Times"))
windowsFonts("Helvetica" = windowsFont("Helvetica"))
当我包含这些语句时,我没有收到错误消息,并且不同的节点类型以不同的字体显示。
关于r - 在二分网络图中使用不同的字体作为顶点标签(Rstudio),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56332093/