如何在 Vega-lite 轴标题中换行?

How can I put a line break in a Vega-lite axis title?

我是 Vega-lite 的新手,我想弄清楚轴标题是否可以换行。我有一个长轴标题,例如:

"Long axis title is too long to fit under the graph"

我试过:

"Long axis title is too\n long to fit under the graph" 和
"长轴标题太\
长以适合图表

“\n”似乎没有做任何事情。 "\[enter]" 只是向该行添加了额外的 space。

我的 x 和 y 编码如下所示:

encoding: {
      x: {field: 'a',
          type: 'ordinal',
          sort: {"encoding": "x"},  
          axis: {"title": "Knowledge of the elder\
          categories would melt\
          your psyche",
          "titleFontSize": 30,
          }
          },
      y: {field: 'b', 
          type: 'quantitative',
          axis: {"title": "Your puny mortal mind\ncannot comprehend the units\nof the multiverse!",
          "titleFontSize": 14,
          }
          }
    }

我没有收到错误消息,但也没有换行符。我要么没有得到任何改变(来自 \n),要么没有得到奇怪的间距(来自 [enter])。

谢谢!

在Vega-Lite 4.0 或更高版本中,可以通过传递字符串数组在标题中指定多行文本。例如:

{"data": {
    "values": [
      {"a": "A", "b": 28},
      {"a": "B", "b": 55},
      {"a": "C", "b": 43},
      {"a": "D", "b": 91},
      {"a": "E", "b": 81},
      {"a": "F", "b": 53},
      {"a": "G", "b": 19},
      {"a": "H", "b": 87},
      {"a": "I", "b": 52}
    ]
  },
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "a",
      "type": "ordinal",
      "title": ["First line of title", "second line of title"]
    },
    "y": {"field": "b", "type": "quantitative"}
  }
}