Stefan_W
Stefan_W

Reputation: 173

Using different fonts for vertex labels in bipartite network graph (Rstudio)

I want to use different fonts for the vertex labels in a bipartite network graph in R. The first colum is the name of a person and the second column is the organisation to which the person is affiliated (double affiliation is possible).

This is an example of the data

# 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]
)


I assign two font styles (no special ones) to the data that these are recognised in the plot. However, the following error occurs and I don't know how to solve this:

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)


I could not find any related question here.
Thank you for your help and suggestions in advance!

Upvotes: 2

Views: 573

Answers (1)

G5W
G5W

Reputation: 37661

If I just run your code, I get a similar error message, but you can fix this by including these statements before your plot statement.

windowsFonts("Times" = windowsFont("Times"))
windowsFonts("Helvetica" = windowsFont("Helvetica"))

When I included these statements, I got no error message and the different node types were displayed with different fonts.

Graph with multiple fonts in vertex labels

Upvotes: 2

Related Questions