networkD3 icon indicating copy to clipboard operation
networkD3 copied to clipboard

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

Open aaronxs opened this issue 7 years ago • 2 comments

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 avatar Jul 05 '18 18:07 aaronxs

@timdisher thought you might be interested in this as well

aaronxs avatar Jul 06 '18 12:07 aaronxs

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

cjyetman avatar Apr 10 '19 06:04 cjyetman