我正在[HOST]/de-DE
[HOST]/sv-SE
[HOST]/fr-BE
[HOST]/nl-BE
plotly
和heatmap
树状图上一起绘制ggplot2
处理了一点(与heatmaply
不兼容)机器没有linux
并遇到错误:
以下是代码:
X11
在没有library(ggplot2)
library(plotly)
library(dendextend)
#dendogram data
set.seed(1)
my.mat <- matrix(rnorm(10*100),nrow=100,ncol=10,dimnames = list(paste("g",1:100,sep=""),paste("s",1:10,sep="")))
my.hover.mat <- matrix(paste(paste(rownames(my.mat),paste("description",1:100,sep=" "),sep=":"),colnames(my.mat),signif(my.mat,3),sep="'</br>'"),nrow=100,ncol=10)
x <- as.matrix(scale(my.mat))
dd.col <- as.dendrogram(hclust(dist(x)))
dd.row <- as.dendrogram(hclust(dist(t(x))))
#cut dd.col
dd.col <- cut(dd.col,h=6)$upper
ggdend.col <- as.ggdend(dd.col)
leaf.heights <- dplyr::filter(ggdend.col$nodes,!is.na(leaf))$height
leaf.seqments.idx <- which(ggdend.col$segments$yend %in% leaf.heights)
ggdend.col$segments$yend[leaf.seqments.idx] <- max(ggdend.col$segments$yend[leaf.seqments.idx])
ggdend.col$segments$col[leaf.seqments.idx] <- "black"
ggdend.col$labels$label <- 1:nrow(ggdend.col$labels)
ggdend.col$labels$y <- max(ggdend.col$segments$yend[leaf.seqments.idx])
ggdend.col$labels$x <- ggdend.col$segments$x[leaf.seqments.idx]
ggdend.col$labels$col <- "black"
ggdend.col$segments$lwd <- 0.5
ggdend.row <- dendro_data(dd.row)
ggdend.row$labels$label <- ""
ggdend.row$labels$col <- "black"
ggdend.row$segments$lwd <- 0.5
#ggplot dendrograms
py <- ggplot()+geom_segment(data=ggdend.col$segments,aes(x=x,y=y,xend=xend,yend=yend))+coord_flip()+annotate("text",size=4,hjust=1,x=ggdend.col$label$x,y=ggdend.col$label$y,label=ggdend.col$label$label,colour=ggdend.col$label$col)+labs(x="",y="")+
theme_minimal()+theme(axis.text=element_blank(),axis.ticks=element_blank(),panel.grid=element_blank())
px <- ggplot()+geom_segment(data=ggdend.row$segments,aes(x=x,y=y,xend=xend,yend=yend))+annotate("text",size=4,hjust=1,x=ggdend.row$label$x,y=ggdend.row$label$y,label=ggdend.row$label$label,colour=ggdend.row$label$col)+labs(x="",y="")+
labs(x="",y="")+theme_minimal()+theme(axis.text=element_blank(),axis.ticks=element_blank(),panel.grid=element_blank())
# heatmap
col.ord <- order.dendrogram(dd.col)
row.ord <- order.dendrogram(dd.row)
my.mat <- my.mat[col.ord,row.ord]
my.hover.mat <- my.hover.mat[col.ord,row.ord]
heatmap.plotly <- plot_ly() %>% add_heatmap(z=~my.mat,x=factor(colnames(my.mat),lev=colnames(my.mat)),y=factor(rownames(my.mat),lev=rownames(my.mat)),hoverinfo='text',text=my.hover.mat)
# plotting it all together
eaxis <- list(showticklabels = FALSE,showgrid = FALSE,zeroline = FALSE)
p_empty <- plot_ly(filename="r-docs/dendrogram") %>% layout(margin = list(l = 200),xaxis = eaxis,yaxis = eaxis)
all.together <- plotly::subplot(px, p_empty, heatmap.plotly, py, nrows = 2, margin = 0.01)
的{{1}}计算机上,linux
对象转换为X11
对象,发生在ggplot2
命令,崩溃时出现此错误消息:
plotly
如果我尝试将树形图plotly::subplot
对象:Error in .External2(C_X11, paste("png::", filename, sep = ""), g$width, :
unable to start device PNG
[1]: https://i.stack.imgur.com/UhKg7.png
和ggplot
转换为px
个对象,则会获得相同的错误:
py
所以这不是我问题的解决方案。
所以我的问题是:
是否有解决plotly
问题的方法?我无法在我的机器上安装> plotly_build(py)
Error in .External2(C_X11, paste("png::", filename, sep = ""), g$width, :
unable to start device PNG
,因此无法解决问题。
也许可以直接或从X11
或X11
对象生成plotly
dendrogram
- 即无需转换dendrogram
到ggdend
个对象。