##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)
在第一帧中,我想放置热图,在第二帧中放置图例
但我不工作
seq_heatmap(seq,seq.hclust)
seqlegend(seq)