2016-04-11 37 views
1

我的數據由多個類別(在本例中爲三個類別)的測試對象組成,但這些類別基於三個時間點:基因型,早期表型和晚期表型階段。創建一個包含三列的轉換圖

這裏是樣本數據:

genotype<-cbind(c(rep("A",100),rep("B",100),rep("C",100))) 
early_phenotype<-cbind(c(rep("A",75),rep("B",75),rep("C",75),rep("A",75))) 
late_phenotype<-cbind(c(rep("A",50),rep("B",100),rep("C",100),rep("A",50))) 
df<-cbind(genotype,early_phenotype,late_phenotype) 
df<-as.data.frame(df) 
colnames(df)<-c("genotype","early_phenotype","late_phenotype") 

我想生產什麼通常稱爲一個「過渡的情節」。我已經得到了最接近的是這樣的:

library(Gmisc) 
transitionPlot(table(df[,1:2]), txt_start_clr = "black", txt_end_clr = "black", fill_start_box = "white", fill_end_box = "white") 

...它生產這個情節: enter image description here

但我想實現兩件事情,這個陰謀沒有:

  1. 我想要兩列以上,在這個例子中有三列:基因型,早期表型和晚期表型。在這個例子中,它應該是這樣的(我在Photoshop中實現這一點,沒有R) enter image description here

  2. 而是單箭頭與連接兩盒不同的權重,我寧願有抖動/透明度的多重箭其中每個箭頭將是一個單獨的觀察,似乎是這樣的: enter image description here

有什麼建議?

P.S.我並不在乎箱子的彎曲邊緣,也不在乎幻想的陰影。

+0

使用[Gmisc :: Transition-class](https://cran.r-project.org/web/packages/Gmisc/vignettes/Transition-class.html)可能會出現超過2列 –

回答

3
  1. 我想兩個以上的列,在這個例子中三列
  2. 而是單箭頭以不同的權重連接兩個 盒,我寧願有多重箭

也許試試用igraph

m <- sapply(1:3, function(x) paste0(df[, x], x)) 
el <- rbind(m[, 1:2], m[, 2:3]) 
library(igraph) 
g <- graph_from_edgelist(el) 
coords <- layout.norm(t(sapply(strsplit(V(g)$name, ""), function(x) as.numeric(c(-match(x[1], LETTERS), x[2]))))) 
plot(g, layout=coords[, 2:1]) 

enter image description here

+0

看起來很有前途,從來沒有聽說過'igraph'。有沒有辦法改變梭形箭頭以減少壓倒性的影響?真實的數據有1000多個觀測值,所以我寧願使用alpha /透明度(我在上面的文章中添加了樣本圖片) – Oposum

+0

看看'?igraph.plotting' - 你可以添加'edge.arrow.size = 0.5'來減小箭頭大小。看起來好像一個帶有alpha的'edge.color'(例如「#99999966」)不起作用。 – lukeA

+0

我看到,沒有alpha,但它看起來像一個實心的主軸 – Oposum

相關問題