R 中的 plotly 热图 - 更改比例标题

plotly heatmap in R - change scale title

我已经使用 plot_ly 在 R 中创建了一个热图,但我终生无法弄清楚如何更改颜色图例上方出现的名称(除了更改名称输入数据帧)。

问题是,我希望标题名称中有空格,这很难作为数据传递给 plotly 调用。

必须有一种方法可以直接编辑它,就像每个其他 label/title 一样?!

我希望它会继承自 legend= 但似乎没有。下面的代码和输出图像(试图更改当前显示 "data.matrix, adjwallace" 的位)。

(我没有提供数据,因为它与我不认为的特定问题无关 - 我不得不弄乱它的格式,但如果需要我可以编辑)。

fonts <- list(
family = "sans-serif",
size = 12
)

x.axisSettings <- list(
 title = "",
 zeroline = FALSE,
 showline = FALSE,
 showticklabels = TRUE,
 showgrid = FALSE,
)

y.axisSettings <- list(
  title = "",
  zeroline = FALSE,
  showline = FALSE,
  showticklabels = TRUE,
  showgrid = FALSE,
)

legend.Settings <- list(
  font = fonts,
  title = "Adjusted Wallace Coefficients"
)

plot_ly(z = data.matrix(adjwallace),
        colorscale= "Hot",
        name = "Adjusted Wallace Coefficients",
        x = names(adjwallace),
        y = names(adjwallace),
        type = "heatmap") %>%
  layout(xaxis=x.axisSettings,
         yaxis=y.axisSettings,
         legend=legend.Settings)

只需在 colorbar 参数中指定标题即可。有关详细信息,请参阅 here...

library(plotly)

data("edhec", package = "PerformanceAnalytics")

plot_ly(z = cov(edhec), type = "heatmap", 
        colorbar = list(title = "Edhec Covariance"))