如何使用 visIgraph 修改节点标签的字体大小?
How can I modify the font size of the node labels with visIgraph?
我正在绘制我通过 igraph
包使用 visNetwork::visIgraph
和 have seen 构建的图表,font.size
通常用作控制大小的参数标签,但在我的代码中无法构建可视化效果,如下所示。
如何更改以下代码中标签的字体大小?
library(igraph)
library(visNetwork)
rnd_dag <- function(p = 25, seed = 123, p_edge = 0.2) {
if (seed) set.seed(seed)
A <- matrix(0, p, p)
A[lower.tri(A)] <- sample(c(0, 1), p*(p-1)/2, replace = TRUE,
prob = c(1 - p_edge, p_edge))
return(A)
}
rnd_dag(25, p_edge = 0.1) %>%
graph_from_adjacency_matrix %>%
visIgraph(layout = "layout_with_sugiyama")
您无法控制字体大小的原因是您的标签 integer-type。标签必须是 character-type 才能将标签识别为标签。
x = rnd_dag(25, p_edge = 0.1) %>%
graph_from_adjacency_matrix %>%
visIgraph(layout = "layout_with_sugiyama") %>%
visNodes(font = list(size = 50))
x$x$nodes$label <- as.character(1:25) # change labels to character-type
x
我正在绘制我通过 igraph
包使用 visNetwork::visIgraph
和 have seen 构建的图表,font.size
通常用作控制大小的参数标签,但在我的代码中无法构建可视化效果,如下所示。
如何更改以下代码中标签的字体大小?
library(igraph)
library(visNetwork)
rnd_dag <- function(p = 25, seed = 123, p_edge = 0.2) {
if (seed) set.seed(seed)
A <- matrix(0, p, p)
A[lower.tri(A)] <- sample(c(0, 1), p*(p-1)/2, replace = TRUE,
prob = c(1 - p_edge, p_edge))
return(A)
}
rnd_dag(25, p_edge = 0.1) %>%
graph_from_adjacency_matrix %>%
visIgraph(layout = "layout_with_sugiyama")
您无法控制字体大小的原因是您的标签 integer-type。标签必须是 character-type 才能将标签识别为标签。
x = rnd_dag(25, p_edge = 0.1) %>%
graph_from_adjacency_matrix %>%
visIgraph(layout = "layout_with_sugiyama") %>%
visNodes(font = list(size = 50))
x$x$nodes$label <- as.character(1:25) # change labels to character-type
x