我有一个矩阵(来自若干情况下的基因表达):
set.seed(1)
mat <- matrix(rnorm(50*10),nrow=50,ncol=10,dimnames=list(paste("C",1:50,sep="."),paste("G",1:10,sep=".")))
我希望使用plotly
在R
中绘制一个heatmap
。
require(plotly)
heatmap.plotly <- plot_ly(x=colnames(mat),y=rownames(mat),z=mat,type="heatmap",colors=colorRamp(c("darkblue","white","darkred")),colorbar=list(title="Score",len=0.4)) %>%
layout(yaxis=list(title="Condition"),xaxis=list(title="Gene"))
很好用。
但是,我想添加只在悬停时可见的文本。
我以为这样会起作用:
conditions.text <- paste(paste("C",1:50,sep="."),rep(paste(LETTERS[sample(26,10,replace=T)],collapse=""),50),sep=":")
heatmap.plotly <- plot_ly(x=colnames(mat),y=rownames(mat),z=mat,type="heatmap",colors=colorRamp(c("darkblue","white","darkred")),colorbar=list(title="Score",len=0.4),hoverinfo='text',text=~conditions.text) %>%
layout(yaxis=list(title="Condition"),xaxis=list(title="Gene"))
但是它并没有显示任何文本。当悬停在图表上时,我实际上看不到任何文本。
请注意,我正在使用一个矩阵而不是一个融合的数据框。