Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plotly heatmap in R - change scale title

Tags:

r

plotly

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).

Trouble is, I'd like spaces in the name of the title, which passing as the data to the plotly call makes difficult.

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").

(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)

enter image description here

like image 383
Joe Healey Avatar asked Dec 19 '22 17:12

Joe Healey


1 Answers

Just specify the title inside the colorbar argument. See here for more details...

library(plotly)

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

plot_ly(z = cov(edhec), type = "heatmap", 
        colorbar = list(title = "Edhec Covariance"))
like image 180
royr2 Avatar answered Jan 02 '23 02:01

royr2