Lizbeth Montes
Lizbeth Montes

Reputation: 153

Modifying labels (x,y,z) in heatmap on plotly?

I want to rename labels in a heatmap. for example: instead of the label says "x:", I want the label to say "Hour:" instead of the label says "y:", I want the label to say "Day:"

Library(plotly)

p <- plot_ly(z = volcano, colors = colorRamp(c("red", "green")), type = "heatmap")

enter image description here furthermore, it would be useful, for example if we use a transformation of data in order to intensify contrast, still the html interactive label show real data.

Example

Upvotes: 4

Views: 1684

Answers (1)

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

Reputation: 84519

What about

library(plotly)
dat <- expand.grid(x = 1:nrow(volcano), y = 1:ncol(volcano))
dat$z <- c(volcano)

plot_ly(height = 500) %>%
  layout(autosize = FALSE, 
         xaxis=list(title = "Hour", titlefont = list(size=20)),
         yaxis=list(title = "Day", titlefont = list(size=20))) %>%
  add_trace(data = dat, x = ~x, y = ~y, z = ~z, type = "heatmap",
            hoverinfo = 'text',
            text = ~paste("Hour:", dat$x,
                          "<br> Day:", dat$y,
                          "<br> z:", dat$z))

enter image description here

Upvotes: 3

Related Questions