[英]R ggraph / igraph geom_edge_link2 define custom color for factor variable
我正在嘗試更改邊緣的顏色。 目前圖表顯示如下
雖然根據圖形屬性“Polarität”(極性)對邊緣進行着色,但我想將其從默認的 ggplot 紅色和藍色配色方案中切換。 我對如何做到這一點感到困惑。
提前致謝
ggraph <- ggraph(cog_tidy, layout = 'nicely',) +
theme_graph()+
scale_colour_brewer(palette = "Dark2") +
geom_edge_link2(
aes(end_cap = circle(6, "pt"), edge_color = Polarität ,width=Gewichtung),
arrow = arrow(
angle = 10,
length = unit(0.1, "inches"),
ends = "last",
type = "closed"
)
)+
geom_node_point( aes(size = Gradzentralität ,color = Kategorie), show.legend = TRUE) +
geom_node_text(aes(label = label), repel=TRUE, position = "identity", size=2) +
scale_edge_width(range = c(0.1, 1))
您可以通過scale_edge_color_xxx
系列函數設置用於邊緣的顏色。 請參閱https://ggraph.data-imaginist.com/reference/index.html#section-scales 。
從?geom_edge_link2
和scale_edge_color_manual
調整默認示例,您可以分配特定的顏色,如下所示:
library(ggraph, warn = FALSE)
#> Loading required package: ggplot2
library(tidygraph, warn = FALSE)
set.seed(1)
gr <- create_notable('bull') %>%
mutate(class = sample(letters[1:3], n(), replace = TRUE)) %>%
activate(edges) %>%
mutate(class = sample(letters[1:3], n(), replace = TRUE))
ggraph(gr, 'stress') +
geom_edge_link2(aes(edge_color = node.class)) +
scale_edge_color_manual(values = c(a = "purple", b = "orange", c = "black"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.