【发布时间】:2017-08-01 07:08:27
【问题描述】:
我有一个matrix(几种情况下的基因表达):
set.seed(1)
mat <- matrix(rnorm(50*10),nrow=50,ncol=10,dimnames=list(paste("C",1:50,sep="."),paste("G",1:10,sep=".")))
我想在R 中使用plotly 将其绘制为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"))
但事实并非如此。将鼠标悬停在绘图上时,我实际上没有看到任何文字。
请注意,我使用的是 matrix 而不是 melted data.frame。
【问题讨论】: