christophergandrud / networkD3

D3 JavaScript Network Graphs from R
http://christophergandrud.github.io/networkD3
652 stars 269 forks source link

Customizing the label/text for each link in sankeyNetwork output? #239

Open aaronxs opened 6 years ago

aaronxs commented 6 years ago

Hi,

Thank you for such a great package!!

I am trying to create a network/flow diagram that shows how drugs are connected (through clinical trials). The nodes here are the drugs, the colour of the nodes represent the type of the drug. The links connecting the nodes (drugs) represent the trials involving the drugs so links with the same colour means they are the same clinical trial.

The question I have is: would it be possible to edit the texts currently showing when you hover around the links? I would like to add the name of the study to each link and also remove the little right arrow currently showing in the label of the links since it's kind of misleading in this case to say "Drug1 => Drug2".

Here are the codes and data sets I used in the example:

library(networkD3);library(tidyverse);library(magrittr)

# dataframe with the  treatments names (the nodes)
trt <- read.table("TreatmentCoding1.txt", stringsAsFactors = FALSE, header = T)
# dataframe with all the studies (the links)
datt <- read.table("Sample_Data_Pair1.txt", stringsAsFactors = FALSE, header = T)
datt %<>%
  # zero-indexing the treatments in links
  mutate(treat1 = treat1 - 1,
         treat2 = treat2 - 1)

sankeyNetwork(Links = datt,
              Source = "treat1", Target = "treat2", Value = "patient_count", LinkGroup = "study",
              Nodes = trt,
              NodeID = "name", NodeGroup = "drug_type", nodeWidth = 30,
              fontSize = 12,
              units = "patients")

TreatmentCoding1.txt

Sample_Data_Pair1.txt

Thank you! Aaron

aaronxs commented 6 years ago

@timdisher thought you might be interested in this as well

cjyetman commented 5 years ago

This should follow the same strategy as determined for node tooltips in #251