TraMineR我想用包 ( )繪制兩個序列分布圖,seqplot(type = 'd')在它們下面繪制兩個對應于序列圖的隱馬爾可夫模型(那些是簇)。
對于 reprex,我只使用內置biofam資料集。使用layout()產生所需的結果直到第三個圖。第四個圖被繪制到一個新頁面,所以右下角的空間基本上是空的,但前三個窗格是根據layout()規范使用的。
library('seqHMM')
library('TraMineR')
data("biofam")
biofam <- biofam[sample(nrow(biofam),300),]
biofam.lab <- c("Parent", "Left", "Married", "Left Marr",
"Child", "Left Child", "Left Marr Child", "Divorced")
biofam.seq <- seqdef(biofam, 10:25, labels=biofam.lab)
#> [>] 8 distinct states appear in the data:
#> 1 = 0
#> 2 = 1
#> 3 = 2
#> 4 = 3
#> 5 = 4
#> 6 = 5
#> 7 = 6
#> 8 = 7
#> [>] state coding:
#> [alphabet] [label] [long label]
#> 1 0 0 Parent
#> 2 1 1 Left
#> 3 2 2 Married
#> 4 3 3 Left Marr
#> 5 4 4 Child
#> 6 5 5 Left Child
#> 7 6 6 Left Marr Child
#> 8 7 7 Divorced
#> [>] 300 sequences in the data set
#> [>] min/max sequence length: 16/16
### Plot the sequence
seqplot(biofam.seq,type='d',with.legend=FALSE)
### Fit a Hidden Markov Model
biofam.hmm <- build_hmm(observations = biofam.seq, n_states = 3)
### Plot the HMM once
plot(biofam.hmm, with.legend=FALSE)
### Use layout to plot two sequence distribution plots and below there HMM
layout(matrix(c(1,2,3,4), ncol = 2, byrow = TRUE))
layout.show(4)
par(cex = 0.65, mar = c(2.5,4.1,2.5,1.5))
### The Sequence plots
seqplot(biofam.seq, type = 'd', with.legend = FALSE, border = NA, ylab = NA)
seqplot(biofam.seq, type = 'd', with.legend = FALSE, border = NA, ylab = NA)
### Change the par() arguments
par(cex = 0.5, mar = c(1.5,3.5,3.5,1.5))
plot(biofam.hmm, with.legend = FALSE, vertex.size = 15)
plot(biofam.hmm, with.legend = FALSE, vertex.size = 15)
由
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/536372.html
標籤:r阴谋布局培训师序列号
