简体   繁体   English

R中的情节热图 - 改变比例标题

[英]plotly heatmap in R - change scale title

I've created a heat map in R using plot_ly , but I can't for the life of me figure out how to change the name that appears above the colour legend (short of changing the name of the input dataframe). 我使用plot_ly在R中创建了一个热图,但我不能为我的生活找出如何更改颜色图例上方显示的名称(更改输入数据框的名称)。

Trouble is, I'd like spaces in the name of the title, which passing as the data to the plotly call makes difficult. 麻烦的是,我想要标题名称中的空格,因为数据传递给plotly调用变得困难。

There MUST be a way to edit it directly as there is for every other label/title surely?! 必须有一种方法来直接编辑它,因为肯定会有其他标签/标题吗?!

I was hoping it would inherit from legend= but seemingly no.. Code and output image below (trying to change the bit that currently says "data.matrix, adjwallace"). 我希望它会继承legend=但看似没有..下面的代码和输出图像(试图改变当前说“data.matrix,adjwallace”的位)。

(I havent provided the data, since it isn't relevant to the particular problem I don't think - and I had to mess with it's format, but I can edit if necessary). (我没有提供数据,因为它与我不认为的特定问题无关 - 我不得不弄乱它的格式,但我可以根据需要进行编辑)。

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)

在此输入图像描述

Just specify the title inside the colorbar argument. 只需在colorbar参数中指定标题即可。 See here for more details... 有关详细信息,请参见此处

library(plotly)

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM