Patricia Bermudi
Patricia Bermudi

Reputation: 147

How to add a line break in Highchart legend in R?

I made an org chart and I need to manually determine the line breaks of text.

I'm using paste() to join a text with the value of an object. But the break isn't working.

Follow the example:

library(highcharter)
library(tidyverse)

value <-  1
  
  highchart() %>%
    hc_chart(type = 'organization') %>%
    hc_add_series(
      data = list(
        list(from = 'A1', to = 'A2'),
        list(from = 'A2', to = 'A3')),
      nodes = list(
        list(id = 'A1', name = paste("I need to break the text", value,  sep="\n"))), #TEXT
      nodeWidth = 150) # increasing the width of the box, to illustrate

enter image description here

Upvotes: 1

Views: 220

Answers (1)

stefan
stefan

Reputation: 125897

Instead of using \n use the html tag <br> as separator:

library(highcharter)
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
library(tidyverse)

value <-  1

highchart() %>%
  hc_chart(type = 'organization') %>%
  hc_add_series(
    data = list(
      list(from = 'A1', to = 'A2'),
      list(from = 'A2', to = 'A3')),
    nodes = list(
      list(id = 'A1', name = paste("I need to break the text", value,  sep="<br>"))), #TEXT
    nodeWidth = 150) # increasing the width of the box, to illustrate

enter image description here

Upvotes: 1

Related Questions