简体   繁体   English

如何从ggraph图例中删除“a”?

[英]How to have “a” removed from a ggraph plot legend?

Can the letter "a" be removed from the legend associated with eg a fill or colour aesthetic, in a ggraph network plot, like in the simple example below ? 可以在字母“a”从与例如相关的传说被移除fillcolour美学,在ggraph在下面的简单示例网络的情节,怎么样?

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()

In the case of geom_text , show.legend = FALSE solves it, geom_text的情况下, show.legend = FALSE解决它,

Remove 'a' from legend when using aesthetics and geom_text 使用美学和geom_text时,从图例中删除“a”

but adding show.legend = FALSE within geom_node_label() , removes the legend completely. 但是在geom_node_label()添加show.legend = FALSE会完全删除图例。

is there any solution for this in ggraph ? ggraph有什么解决方案吗?

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. 根据上述注释回答原始问题:根据@ user20650解决方案,必须在脚本顶部添加以下代码行。

library(grid)
GeomLabel$draw_key <- function (data, params, size) { draw_key_rect(data) }

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. 如果在geom_node_label使用了geom_node_label repel = TRUE参数,那么除了上面的GeomLabelRepel$draw_key <- GeomLabel$draw_key需要添加GeomLabelRepel$draw_key <- GeomLabel$draw_key

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM