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)
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"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With