Plotly热图列的顺序

时间:2017-03-18 21:58:15

标签: r heatmap plotly

可能很简单:

我有一个NA&#39的数字矩阵:

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

答案 0 :(得分:1)

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

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