首页 > 解决方案 > 如何在 R 的 Highchart 图例中添加换行符?

问题描述

我制作了一个组织结构图,我需要手动确定文本的换行符。

我正在使用 paste() 将文本与对象的值连接起来。但休息不起作用。

根据例子:

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

在此处输入图像描述

标签: rhighcharts

解决方案


而不是\n使用 html 标签<br>作为分隔符:

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

在此处输入图像描述


推荐阅读