1

I have a problem with wrapping of a long text (separated by a semicolon) in chordNetwork (in the package) labels.

I tried paste "\n" after semicolon but didn't work.

Result which I want in label:

xxxxxxxxxxxxxxxxxxxxxxxxxx; 
yyyyyyyyyyyyyyyyyy 

Here is the code:

# create a simple data frame
d2 <- data.frame(from=LETTERS[1:5],to=c("xxxxxxxxxxxxxxxxxxxxxxxxxx;\n yyyyyyyyyyyyyyyyyy","X","X","Y","Y"),v=runif(5),stringsAsFactors = F)
d2
# convert data frame into  a square matrix for chordNetwork data structure
d2 <- rbind(d2, data.frame(from=d2$to,to=d2$from,v=NA))
d2
str(d2)

library(tidyr)
library(dplyr)
library(networkD3)

d2 %>%  spread(key = to,value = v) %>% select(-from) %>% as.matrix() ->d2
rownames(d2) <- colnames(d2)
d2;dim(d2)

chordNetwork(d2, height = 500, width = 500, initialOpacity = 0.8,
             useTicks = 0,  padding = 0.1, fontSize = 9,
             fontFamily = "sans-serif", labels = colnames(d2), labelDistance = 0) 
CJ Yetman
  • 8,373
  • 2
  • 24
  • 56
Edvardoss
  • 393
  • 3
  • 8

1 Answers1

0

SVG text elements do not support linebreaks. see, for instance...

How to linebreak an svg text within javascript?

How to display multiple lines of text in SVG?

CJ Yetman
  • 8,373
  • 2
  • 24
  • 56