R 绘图热图刻度标签被切断

问题描述 投票:0回答:1

尝试使用

R
plotly
生成基因表达热图。基因名字很长,尺寸也很大:

require(permute)
require(plotly)
set.seed(1)
mat <- matrix(shuffle(c(rnorm(5000,2,1),rnorm(5000,-2,1))),nrow=2500,ncol=4)
rownames(mat) <- paste("very_long_gene_name",1:2500,sep=".")
colnames(mat) <- paste("s",1:4,sep=".")

聚类:

hc.col <- hclust(dist(t(mat)))
dd.col <- as.dendrogram(hc.col)
col.order <- order.dendrogram(dd.col)
hc.row <- hclust(dist(mat))
dd.row <- as.dendrogram(hc.row)
row.order <- order.dendrogram(dd.row)
mat <- mat[row.order,col.order]

生成绘图并保存 html 文件:

heatmap.plotly <- plot_ly(x=colnames(mat),y=rownames(mat),z=mat,type="heatmap",colors=colorRamp(c("darkblue","white","darkred")))
htmlwidgets::saveWidget(heatmap.plotly,"heatmap.plotly.html")

我得到的图中基因名称被截断,我不确定它是否显示了所有数据: enter image description here

知道如何解决这两个问题吗?

r heatmap plotly
1个回答
3
投票

增加利润

m <- list(
  l = 200,
  r = 10,
  b = 50,
  t = 10,
  pad = 2
)
heatmap.plotly <- plot_ly(x=colnames(mat),y=rownames(mat),z=mat,type="heatmap",
    colors=colorRamp(c("darkblue","white","darkred"))) %>%
    layout(margin = m)

heatmap.plotly
© www.soinside.com 2019 - 2024. All rights reserved.