有没有办法在可绘制的热图的右侧移动行标签?

时间:2019-01-12 17:01:16

标签: r 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 个答案:

答案 0 :(得分:2)

为此,我们可以使用yaxis = list(side = "right")并使用colorbar = list(x = -0.4)调整颜色栏的位置(您可能需要在特定图形中使用此值稍微花一点时间):

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