情节热图削减了y轴名称

时间:2019-01-22 14:33:39

标签: r plotly

我用下面的代码绘制了一个热图。如您在所附的屏幕截图中所见,y轴名称未完整显示。我不知道如何在不减少字体的情况下解决此问题。是一种使热图更接近颜色栏或减小其宽度的解决方案吗?enter image description here

#data

Database1<-c(1,-2,-3,2,-3,5)
Database2<-c(2,-3,5,2,-3,5)
Database3<-c(3,-5,5,2,-3,5)
Database4<-c(1,-2,-3,2,-3,5)
Database5<-c(2,-3,5,2,-3,5)
Database6<-c(3,-5,5,2,-3,5)
D<-data.frame(Database1,Database2,Database3,Database4,Database5,Database6)
D<-as.matrix(D)
rownames(D)<-c("Database1","Database2","Database3","Database4","Database5","Database6")

#heatmap
library(plotly)
plot_ly(x=colnames(D), y=rownames(D), z = data,colors = colorRamp(c("red","blue")), type = "heatmap",colorbar = list(x = -0.4)) %>%
    layout(
      xaxis=list(tickangle = 45, autorange = "reversed"),
      yaxis = list(side = "right"),
      margin = list(l = 150, r = 50, b = 150, t = 0, pad = 4))

1 个答案:

答案 0 :(得分:1)

要将colorbar移近热图,请更改colorbar = list(x = ...)。在这里,您需要的位置小于0(设置为-0.1)。要将图扩展为右移r中的margin。使用了150(与左边距相同)。

library(plotly)
plot_ly(x = colnames(D), y = rownames(D), z = D,
        colors = colorRamp(c("red", "blue")), type = "heatmap",
        colorbar = list(x = -0.1)) %>%
    layout(xaxis = list(tickangle = 45, autorange = "reversed"),
           yaxis = list(side = "right"),
           margin = list(l = 150, r = 150, b = 150, t = 0, pad = 4)
    )

enter image description here