Reputation: 8404
I create a heatmap with plotly with the code below. As you can see in the screenshot attached the y-axis names are not displayed in their full length. I wonder how I will be able to fix this without reducing their font. Is is a solution to bring the heatmap closer to the colorbar or reduce its width?
#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))
Upvotes: 1
Views: 160
Reputation: 28309
To move colorbar
closer to heatmap change colorbar = list(x = ...)
. Here you need position less than 0 (set to -0.1
). To expand plot to right change r
in margin
. Used 150
(the same as for the left margin).
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)
)
Upvotes: 1