当我使用NetworkD3绘制有向图时,边缘不是定向的,我该如何修复它?一个例子 :
library(networkD3)
data(MisLinks)
data(MisNodes)
forceNetwork(Links = MisLinks, Nodes = MisNodes,
Source = "source", Target = "target",
Value = "value", NodeID = "name",
Group = "group", opacity = 0.8)
Run Code Online (Sandbox Code Playgroud)
我希望结果被定向这是有向图的定义:
"有向图是图形,即连接在一起的一组对象(称为顶点或节点),其中所有边缘都从一个顶点指向另一个顶点.有向图有时被称为有向图或有向网络.
我希望边缘像箭一样,我怎么能在networkD3中做到这一点,我希望它很清楚.
谢谢.
我正在用 R 制作桑基图,但对节点名称背后的含义有疑问。
下面是我在网上找到的一个例子:
library(networkD3)
nodes = data.frame("name" =
c("Node A", # Node 0
"Node B", # Node 1
"Node C", # Node 2
"Node D"))# Node 3
links = as.data.frame(matrix(c(
0, 1, 10, # Each row represents a link. The first number
0, 2, 20, # represents the node being conntected from.
1, 3, 30, # the second number represents the node connected to.
2, 3, 40),# The third number is the value of the node
byrow = TRUE, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用networkD3库在R中构建sankey图。
我有以下数据
print(nodes1)
name
1 as
2 sdf
3 wer
4 xc
5 sd
6 er
print(links)
source target value
1 0 5 112
2 0 4 848
3 0 4 661
4 0 4 33
5 0 3 291
6 1 5 23
7 1 4 983
8 1 3 859
9 1 3 35
10 2 4 537
Run Code Online (Sandbox Code Playgroud)
因此,当我尝试使用以下代码创建sankeyNetwork时
sankeyNetwork(Links = links1, Nodes = nodes1,
Source = "source", Target = "target",
Value = "value", NodeID = "name",
fontSize= …Run Code Online (Sandbox Code Playgroud) countrycode event
1713 ESP 110mh
1009 NED HJ
536 BLR LJ
2882 FRA 1500m
509 EST LJ
2449 BEL PV
1022 EST HJ
2530 USA JT
2714 CUB JT
1236 HUN 400m
238 BLR 100m
2518 USA JT
1575 FRA 110mh
615 JPN LJ
1144 GER HJ
596 CAN LJ
2477 HUN JT
1046 GER HJ
2501 FIN DT
2176 KAZ PV
Run Code Online (Sandbox Code Playgroud)
我想在我的数据框中创建一个新的因子向量eventtype,其中:
具有行100m,400m,110mh,1500m在event可变成为分组为Runs; DT, …
我似乎无法理解如何sunburst在sunburstR包处理某些paramenters中,给它的颜色以及如何应用颜色对不同类别分别是矢量,以及如何显示标签的不同分区。
它是否有逻辑,是否有更好的方法来手动指定哪种颜色应该与哪个根/叶搭配?
来自?sunburst:(不知道他们所说的“提供具有范围和/或域的列表”是什么意思。
colors
vector of strings representing colors as hexadecimal for manual colors.
If you want precise control of colors, supply a list with range and/or domain.
For advanced customization, supply a JavaScript function.
Run Code Online (Sandbox Code Playgroud)
谢谢!
sourcestatus
# A tibble: 5 x 2
SourceStatus count
<chr> <int>
1 blood-affected 4369
2 blood-unaffected 2848
3 blood-unknown 1
4 cell_line-affected 1797
5 cell_line-unaffected 151
Run Code Online (Sandbox Code Playgroud)
创建旭日:
sunburst(sourcestatus, count = TRUE, percent= T,
colors = c("#6b5b95", "#feb236", "#d64161", …Run Code Online (Sandbox Code Playgroud) 我有一个在 R 中创建的 Sankey 图。它生成图,但节点名称放置在右侧节点的节点左侧。我希望所有的名字都在右边,这样真实的名字(更长)就不会相互重叠。
下面是一组完整的工作代码,它们将生成我目前正在使用的图表。
library(networkD3)
nodes <- data.frame('name' =
c('Node0','Node1','Node2','Node3','Node4','Node5','Node6',
'Node7','Node8','Node9','Node10','Node11','Node12','Node13',
'Node14','Node15','Node16','Node17','Node18','Node19',
'Node20','Node21','Node22','Node23','Node24','Node25',
'Node26','Node27','Node28','Node29','Node30','Node31',
'Node32','Node33'))
links = as.data.frame(matrix(c(
0, 3,140,
0, 4,140,
0, 5,140,
0, 6,140,
1, 3,140,
1, 4,140,
1, 5,140,
1, 6,140,
2, 3,140,
2, 4,140,
2, 5,140,
2, 6,140,
3, 7,130,
3, 8,130,
3, 9,50,
3,10,50,
3,11,50,
4,12,140,
4,13,100,
4,14,100,
4,15,80,
5,16,150,
5,17,150,
5,18,60,
5,19,60,
6,20,180,
6,21,80,
6,22,80,
6,23,80,
7,24,13,
7,33,13,
7,31,104,
8,24,13,
8,33,13,
8,26,52,
8,27,52,
9,24,10,
9,33,10,
9,29,30,
9,30,30,
10,24,10,
10,33,10,
10,29,30,
10,30,30,
11,24,10, …Run Code Online (Sandbox Code Playgroud) 我从Internet(链接)上找到了这张图片,我认为它是在R中绘制的。我试图重现此图,并使其与上面的链接中的图大致相似。我使用的代码如下:
ID <- 0:24
NodeGroup <- c(rep(1,8),2,5,rep(4,7),3,5,6,6,7,7,8,9)
name <- c("29581k","5279k","4218k","1917k","1356k","Ventas diversas: 116","Venta diversa: 97","Venta de: 141","Venta totales: 42705","Contribucion marginal: 18183", "17531k","1744k","1326k","1208k","526k","459k","14k","IIBB: 1714","Costo: 22808","Gastos directos: 6734","Gastos distribudos: 2958","Resultado: 8851","Total Gastos: 9332","Imp. Gcias: 3098","Resultado Netto: 5.753")
nodes <- data.frame(ID, name, NodeGroup)
nodes$NodeGroup <- as.character(nodes$NodeGroup)
source <- c(0:7, rep(8,9), 10:16, rep(9,3), 19, 20, 21, 21)
target <- c(rep(8,8), 17, 10:16, 9, rep(18,7), 19:21, rep(22, 2), 23, 24)
value <- c(29581,5279,4218,1917,1356,116,97,141,1714,17531,1744,1326,1208,526,459,14,18138,17531,1744,1326,1208,526,459,14,6374,2958,8851,6374,2958,3098,5753)
group <- c(1:8, rep(9,8), 10, rep(19,7), rep(18,3), rep(23,2), rep(22,2))
links <- …Run Code Online (Sandbox Code Playgroud) r ×7
htmlwidgets ×6
networkd3 ×5
d3.js ×3
donut-chart ×1
dplyr ×1
nodes ×1
recode ×1
tidyverse ×1