在ggplotly中鼠标悬停时显示ggnet2节点的标签

时间:2020-02-26 01:01:53

标签: r ggplotly

我有一个双向网络,其中有少量事件与大量演员相关。这意味着如果我尝试标记图中的每个点,将很难阅读文本。

相反,我想将此信息隐藏在鼠标上。但是,我想不出一种方法来从ggnet2对象中提取ggplotly对象中的信息。我知道我需要填充ggplotly()调用的tooltip参数,但不需要填充。

下面是一个可以使用的示例:

library(network)
library(GGally)
library(plotly)
# weighted adjacency matrix
bip = data.frame(event1 = c(1, 2, 1, 0),
                 event2 = c(0, 0, 3, 0),
                 event3 = c(1, 1, 0, 4),
                 row.names = letters[1:4])

# weighted bipartite network
bip = network(bip,
              matrix.type = "bipartite",
              ignore.eval = FALSE,
              names.eval = "weights")

p <- ggnet2(bip, label = c("event1", "event2", "event3")) +
  theme(legend.position='none')

g <- ggplotly(p, tooltip = "label")

htmlwidgets::saveWidget(g, 'example.html')

如果我忽略了上面代码的tooltip = "label"位,则工具提示将显示以下内容: enter image description here

例如,在本例中,我实际上希望它们显示的是“ A”。包括上面的tooltip参数意味着什么也没有显示,大概是因为它实际上找不到。

这可能吗?我该怎么办?

0 个答案:

没有答案