r - 在二分网络图中使用不同的字体作为顶点标签(Rstudio)

标签 r fonts label igraph

我想对 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"))

当我包含这些语句时,我没有收到错误消息,并且不同的节点类型以不同的字体显示。

Graph with multiple fonts in vertex labels

关于r - 在二分网络图中使用不同的字体作为顶点标签(Rstudio),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56332093/

相关文章:

android - Android 浏览器/GUI(古吉拉特语)上的印度语呈现不当

python - 将文本绘制到图像时出现字体错误

R通过使用列索引从避风港标记的数据框中提取attributes(x)$label

python - yticklabels 在 Pandas 图中截断

algorithm - 饼图图标放置算法

R数据框;获取列中的值范围

R Project 和 MQL4 将 R 中的预测对象转换为向量

r - geom_density() 具有离散 x 轴的分组图不平滑

Bash:无法创建具有 unicode 字符的目录

r - 如何使用不同的 y 轴文本长度获得相同的面板宽度