在图上修改热图中的标签(x,y,z)?

时间:2019-01-21 17:18:09

标签: r plotly r-plotly

我想在热图中重命名标签。例如: 而不是标签说“ x:”,我希望标签说“小时:” 而不是标签上说“ y:”,我希望标签上说“ Day:”

Library(plotly)

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

enter image description here 此外,这将很有用,例如,如果我们使用数据转换以增强对比度,那么html交互式标签仍会显示真实数据。

Example

1 个答案:

答案 0 :(得分:2)

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