问题描述
是否可以将字母"a"从与之相关的图例中删除ggraph
网络图中的fill
或colour
美学,就像下面的简单示例一样?
Can the letter "a" be removed from the legend associated with e.g. a fill
or colour
aesthetic, in a ggraph
network plot, like in the simple example below ?
library(igraph)
library(ggraph)
g1 <- make_ring(6)
vertex_attr(g1) <- list(name = LETTERS[1:6], type =rep(c("typeA", "typeB", "typeC"), 2))
ggraph(g1) + geom_node_label(aes(label = name, fill = type)) +
geom_edge_diagonal() + theme_graph()
在geom_text
的情况下,show.legend = FALSE
解决了该问题,
In the case of geom_text
, show.legend = FALSE
solves it,
,但在geom_node_label()
中添加show.legend = FALSE
,将完全删除图例.
but adding show.legend = FALSE
within geom_node_label()
, removes the legend completely.
ggraph
中对此有任何解决方案吗?
is there any solution for this in ggraph
?
推荐答案
基于上述注释,对原始问题的答案:根据@ user20650解决方案,必须在脚本顶部添加以下代码行.
Answer to the original question based on comments above:The following line of code has to be added on the top of the script as per @user20650 solution.
library(grid)
GeomLabel$draw_key <- function (data, params, size) { draw_key_rect(data) }
如果在geom_node_label
中使用了repel = TRUE
自变量,则除了上述GeomLabelRepel$draw_key <- GeomLabel$draw_key
之外,还需要添加.
If repel = TRUE
argument is used inside geom_node_label
, then in addition to the above GeomLabelRepel$draw_key <- GeomLabel$draw_key
needs to be added.
这篇关于如何拥有“一个"从ggraph图例中删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!