[英]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.