首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在diagrammeR中向图形添加文本

如何在diagrammeR中向图形添加文本
EN

Stack Overflow用户
提问于 2016-06-26 21:12:50
回答 1查看 327关注 0票数 1

我想要创建一个很好的图表来说明我的一些数据。

我已经创建了图表,但是我想在节点中添加一些计算的文本。我该怎么做。

这是我的图表,但是如何/在哪里添加我在R中计算的字段呢?:

代码语言:javascript
复制
library(magrittr)
library(DiagrammeR)

# Create a simple NDF
nodes <-
create_nodes(nodes = c("Index", "Surveillance", "Intervention", "Lost to Follow-up"))
# Create a simple EDF
edges <-
  create_edges(from = c("Index", "Surveillance", "Index", "Surveillance","Intervention","Surveillance","Intervention"),
               to = c("Surveillance", "Intervention", "Lost to Follow-up", "Lost to Follow-up","Intervention","Surveillance","Lost to Follow-up"),
               )

graph <-
  create_graph(
    nodes_df = nodes,
    edges_df = edges,
    graph_attrs = "layout = twopi",
    node_attrs = "fontname = Helvetica",
    edge_attrs = "color = gray20"
  )

# View the graph
render_graph(graph,output = "visNetwork")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-26 22:01:41

代码语言:javascript
复制
require(visNetwork, quietly = TRUE)

nb = "Information here"

nodes <- data.frame(id = 1:5, group = c(rep("A", 2), rep("B", 3)), 
                    title = paste("<p>", 1:5,"<br>",nb, sep = ""), stringsAsFactors = FALSE)
edges <- data.frame(from = c(2,5,3,3), to = c(1,2,4,2))


### USE
visNetwork(nodes, edges, width = "100%") %>% visOptions(highlightNearest = list(enabled =TRUE,algorithm="hierarchical"))

当您在节点上传递鼠标时,您将看到您的信息。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38043234

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档