簡體   English   中英

如何為 ggraph 中的節點和標簽着色

[英]how to color the nodes and labels in ggraph

如何像這樣在ggraph圖中指定邊緣的顏色

library(ggraph)
library(igraph)
df_school = highschool %>% mutate(yr=ifelse(year%%2==0,'purple','blue'))
graph = df_school %>% graph_from_data_frame()
V(graph)$node_label = names(V(graph))
ggraph(graph, layout = 'linear', circular = TRUE) + 
  geom_edge_arc(aes(colour = factor(year))) + 
  geom_node_label(aes(label=node_label), alpha=0.2) + 
  scale_edge_colour_identity() 

這里只有邊緣是彩色的,但我不知道如何對節點或標簽進行編碼,或者使標簽背景半透明。 想知道是否有人可以提供幫助。

您分別控制節點和節點標簽。 前綴是geom_node_ - 有很多選項。 以下代碼生成此圖。

ggraph(graph, layout = 'linear', circular = TRUE) + 
  geom_edge_arc(aes(colour = factor(year))) + 
  geom_node_point(size = 8)+ # add nodes
  geom_node_text(aes(label = name), # add node labels
                 colour = 'white')+
  coord_equal()

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM