TraMineR 图形对 R 的布局没有反应

##PACKAGES
library(tidyverse,quietly=TRUE)
library(TraMineR)
library(WeightedCluster,quietly = TRUE)
library(viridis)
library(seqhandbook,quietly = TRUE)

这是我的数据集的表示:

mydata<-structure(list(T1 = structure(c("ANN","ANN","ANN"
),label = "Type chir. bariat."),T2 = structure(c("ANN","ABL","ANN"),T3 = structure(c("ANN",T4 = structure(c("ANN",T5 = structure(c("ANN",T6 = structure(c("ANN","SLE",T7 = structure(c("ANN","ABL"),T8 = structure(c("ANN",T9 = structure(c("ANN",T10 = structure(c("ANN",T11 = structure(c("ANN","SLE"),T12 = structure(c("ANN",T13 = structure(c("ANN","BPG",T14 = structure(c("ANN",T15 = structure(c("ANN",T16 = structure(c("ANN",T17 = structure(c("ANN",T18 = structure(c("ANN",T19 = structure(c("ANN",T20 = structure(c("ANN",label = "Type chir. bariat.")),row.names = c(NA,-50L),class = c("tbl_df","tbl","data.frame"))

我想绘制一个图形和彼此相邻的图例,因为显然函数 seqheatmap from seqhandbook 不显示图例。

我已经分别完成了这两个操作,并希望使用函数 layout from R base

我用于创建序列的代码

# ALPHABETS AND LABELS
labels <- sort(c("ANN","BPD","DCD"))
etats_lng<-c("Ablation","Anneau","Derivation bilio-pancréatique","By-pass gastrique","Décès","Sleeve")

seq <- seqdef(
  mydata[,paste("T",1:20,sep = "")],alphabet = labels,states = etats_lng,cpal = viridis(6,direction = -1)
)

# distances
couts <- seqsubm(seq,method = "CONSTANT",cval = 2)# Matrice des couts de substitution         
seq.dist<- seqdist(seq,method = "OM",indel = 1,sm = couts)# Distance avec optimal-Matching
seq.hclust <- hclust(as.dist(seq.dist),method = "ward.D2") #Clustering des trajectoire


#SETTING OF LAYOUT
layout.matrix <- matrix(c(1,2),nrow = 1,ncol = 2)
layout(mat = layout.matrix,widths = c(3,1) )# Widths of the two columns
layout.show(2)

在第一帧中,我想放置热图,在第二帧中放置图例

TraMineR 图形对 R 的布局没有反应

但我不工作

seq_heatmap(seq,seq.hclust)
seqlegend(seq)
zhubinlove 回答:TraMineR 图形对 R 的布局没有反应

函数 layout 在您的示例中不起作用,因为 layout 不能嵌套并且 heatmap(由 seq_heatmap 调用)已经使用 layout 生成热量地图。

我看到的唯一解决方案是检索函数 heatmap 的源代码(来自 stats),将其重命名为 myheatmap,然后修改它以添加颜色图例。

检索heatmap的代码

myheatmap <- heatmap
edit(myheatmap)

要使 edit 工作,您可能必须指定编辑器。或者,您可以使用 View 并将内容复制粘贴到您选择的编辑器中。

本文链接:https://www.f2er.com/83447.html

大家都在问