Is there a way to move row labels on the right side of a plotly heatmap?

Viewed 321

I would like to know if it is possible to move the row labels on the right side of the heatmap, rather than on the left side or this cannot be moved in plotly.

data<-as.matrix(mtcars)
data[upper.tri(data)] <- NA

library(plotly)
plot_ly(x=colnames(data), y=rownames(data), z = data,colors = colorRamp(c("red","green")), type = "heatmap") %>%
  layout(
    xaxis=list(tickfont = list(size = 30), tickangle = 45),
    margin = list(l = 150, r = 50, b = 150, t = 0, pad = 4))
1 Answers

For that we may use yaxis = list(side = "right") and adjust the colorbar position with colorbar = list(x = -0.4) (you may need to play a little with this value for your specific graph):

plot_ly(x = colnames(data), y = rownames(data), z = data,
        colors = colorRamp(c("red","green")), 
        type = "heatmap", colorbar = list(x = -0.4)) %>%
  layout(xaxis = list(tickfont = list(size = 30), tickangle = 45), 
         yaxis = list(side = "right"), 
         margin = list(l = 150, r = 50, b = 150, t = 0, pad = 4))

enter image description here

Related