首页 文章

Plotly热图列的顺序[重复]

提问于
浏览
1

这个问题在这里已有答案:

可能很简单:

我有一个NA的数字矩阵:

mat <- matrix(c(NA,NA,NA,NA,NA,NA,NA,19.24,NA,NA,NA,NA,17.67,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,17.67,NA,NA,NA,NA,17.67,NA,NA,NA,NA,NA,NA,17.67,17.67,17.67,17.67,17.67,17.67,17.67,19.24,13.48,NA,NA,NA,NA,17.67,NA,NA,NA,NA,NA,NA,NA,NA,NA,17.67,NA,NA,NA,NA,17.67,NA,NA,NA,NA,NA,NA,NA,17.67,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,13.48),
                     nrow=9,ncol=10)
colnames(mat) <- c("11","5","6","2","10","7","4","3","9","8")
rownames(mat) <- c("biological adhesion","cell adhesion","cell communication",
                   "cell surface receptor signaling pathway","cellular response to stimulus",
                   "signal transduction","signaling","single organism signaling",
                   "single organismal cell-cell adhesion")

我想使用 plotly 将其绘制为热图:

require(plotly)
plot_ly(x=colnames(mat),y=rownames(mat),z=mat,type="heatmap")

enter image description here

但是列标签似乎没有遵循我指定的标签:

> colnames(mat)
 [1] "11" "5"  "6"  "2"  "10" "7"  "4"  "3"  "9"  "8"

任何的想法?

另外,任何使y轴标签完全可见的方法?

1 回答

  • 1

    您必须通过更改以下布局选项指定plotly不应更改类别顺序:

    p <- plot_ly(z = mat, x = colnames(mat), y=rownames(mat),type="heatmap") %>%
      layout(xaxis = list(categoryorder = "trace"))
    p
    

相关问题