Liky
Liky

Reputation: 1247

Control the title and the min/max values of the colorscale for heatmaps

I have the following R code:

library(plotly)
A <- matrix(seq(1, 12), nrow = 4, ncol = 3)
p <- plot_ly(z = t(A), type = "heatmap", colorscale = "Greys")
p

The colorscale range is set by default to minimum and maximum value of the given matrix (in my example 0 to 12). Do you know how to proceed to set the values to min= -20 and max =+20. Also, do you know how to add title on top of the colorbar? enter image description here

Upvotes: 2

Views: 2346

Answers (1)

St&#233;phane Laurent
St&#233;phane Laurent

Reputation: 84519

p <- plot_ly(z = t(A), type = "heatmap", colorscale = "Greys") %>% 
  colorbar(limits = c(-20,20), title = "TITLE")

The title is small. You can increase the font:

colorbar(limits = c(-20,20), title = "TITLE", titlefont = list(size=20))

You can put some HTML in the title, e.g. to have an italic title:

colorbar(limits = c(-20,20), title = "<em>TITLE</em>", titlefont = list(size=20))

You can also change the font family:

colorbar(limits = c(-20,20), title = "TITLE", titlefont = list(size=20, family="Arial"))

See here for details and more options.

Upvotes: 3

Related Questions