2013-07-23 30 views
2

我一直在閱讀Lasagna plotsR。在鏈接的論文附錄中,作者有很多代碼來實現這些圖。但它是一個PDF,我不能複製到RStudio(至少,我還沒有弄清楚如何)。有沒有人把這些變成一個包或者是否有人有更可用的格式的代碼?R的烤寬麪條情節

+3

這些看起來好吃,+1 ...從瀏覽圖。 1,我猜一些有針對性的使用'heatmap()'可能會讓你朝某個方向發展...... – texb

+0

來自文章:「寬麪條圖:意大利麪條圖的一個有趣的替代品」:-) –

+0

不是更容易嘗試聯繫論文的作者? – joran

回答

2

千層麪圖似乎是熱圖,雖然名字很可愛。其他軟件包中的熱圖繪製得非常好。考慮Carl Witthoft指出的代碼中的第一個示例圖。您可以複製它在ggplot這樣的:

## Create the data 
palette <- brewer.pal(4, "PuOr")[-2] 
## the matrix containing data for Figure 02a 
H.mat <- matrix(NA, nrow=4, ncol=6) 
H.mat[1, 1:6] = 100*c(2, 1, 1, 1, 1, 2) 
H.mat[2, 1:6] = 100*c(2, 2, 2, 3, 2, 1) 
H.mat[3, 1:6] = 100*c(2, 2, 1, 1, 1, 3) 
H.mat[4, 1:6] = 100*c(3, 3, 2, 1, 2, 3) 

library(ggplot2) 
library(reshape2) 
rownames(H.mat)<-c('P1','T1','P2','T2') 
colnames(H.mat)<-seq(ncol(H.mat)) 
names(dimnames(H.mat))<-c('Subject','Time') 
H.df<-melt(H.mat) 

取決於你願意,你可以得到不同類型的着色什麼。

# For continuous values. 
ggplot(H.df,aes(x=Time,y=Subject,fill=value)) + geom_tile(colour='black') 

enter image description here

# If you consider the value to be categorical. 
ggplot(H.df,aes(x=Time,y=Subject,fill=factor(value))) + 
    geom_tile(colour='black') 

enter image description here

# If you want those exact colours the author used: 
col<-palette[match(ordered(H.df$value),levels(ordered(H.df$value)))] 
ggplot(H.df,aes(x=Time,y=Subject,fill=col)) + 
    geom_tile(colour='black') + scale_fill_identity() 

enter image description here

+1

我無法弄清楚如何正確使用作者的確切顏色,所以我用了一個俗氣的黑客。如果有人能夠以更自然的方式告訴我如何正確地將自定義顏色饋送到'ggplot',請告訴我,我會改變答案。 – nograpes

+0

我想你已經明白了! –

+0

+1 cheesy hack to lasagna plot :) –

4

要回答這個問題實際:代碼是一個PDF文檔在這裏:http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2937254/bin/NIHMS225391-supplement-1.pdf

而且我很容易選擇的代碼在Adobe Reader和複製/粘貼到文本文件。

+0

Dang。這次工作。謝謝。無論如何,現在對烤寬麪條情節的參考在這裏。但是,考慮到@TexB的評論,我不確定是否應該將其標記爲已回答,因爲可能會有更好的代碼。 –