如何在R的Sankey图上显示频率或值或数字

我想在sankey上显示每个酒吧的编号,就像我上传的图像一样,它代表相关治疗途径的数量。我尝试了很多添加标签的方法,但是在networkD3中不起作用。

enter image description here

图片来源:https://onlinelibrary.wiley.com/doi/full/10.1002/pds.4874

enter code here
 s<-c( "A1","A1","B1","C1","A2","B2","C2","C2")
 t<-c("A2","C3","A3","B3","B3")
 v<-c(4,2,3,1,7,2)
a<- data.frame(s,t,v)
a$s=as.character(a$s) 
a$t=as.character(a$t)

Sankeylinks<-a
Sankeynodes<-data.frame(name=unique(c(Sankeylinks$s,Sankeylinks$t)))

Sankeynodes$index<-0:(nrow(Sankeynodes)-1)   

Sankeylinks<-merge(Sankeylinks,Sankeynodes,by.x="s",by.y="name")

Sankeylinks<-merge(Sankeylinks,by.x="t",by.y="name")

Sankeydata<-Sankeylinks[,c(4,5,3)];
names(Sankeydata)<-c("Source","Target","Value")
Sankeyname<-Sankeynodes[,drop=FALSE]

Sankeyname$type2 <- sub(' .*','',c("A","B","C","A","B")) 


my_color <- 'd3.scaleOrdinal() .domain(["A","C"]) 
                 .range(["#69b3a2","steelblue","red"])'

plot <- sankeyNetwork(Links=Sankeydata,Nodes=Sankeyname,Source="Source",Target="Target",Value="Value",NodeID="type2",fontSize=12,nodeWidt=20,NodeGroup = "type2",sinksRight = FALSE,colourScale = my_color)

 plot  
SinoDinosaur 回答:如何在R的Sankey图上显示频率或值或数字

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3128963.html

大家都在问