R的烤宽面条地块

时间:2013-07-23 20:21:10

标签: r graph

我一直在阅读R中的Lasagna plots。在链接中论文的附录中,作者有很多代码来实现这些图。但它是一个pdf,我不能复制到RStudio(至少,我还没弄明白如何)。有没有人将这些包装成一个包或者是否有人以更有用的格式提供代码?

3 个答案:

答案 0 :(得分:4)

回答实际问题:代码在pdf文档中:http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2937254/bin/NIHMS225391-supplement-1.pdf

我在Adobe Reader中轻松选择了代码并将其复制/粘贴到文本文档中。

答案 1 :(得分: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

答案 2 :(得分:0)

多年以后,基于nograpes的答案开始了一个github回购。

https://github.com/swihart/lasagnar