如何拥有“一个"从ggraph图例中删除? [英] How to have "a" removed from a ggraph plot legend?

查看:72
本文介绍了如何拥有“一个"从ggraph图例中删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将字母"a"从与之相关的图例中删除ggraph网络图中的fillcolour美学,就像下面的简单示例一样?

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,

在使用美学时从图例中删除"a"和geom_text

,但在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图例中删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆