3

我一直在阅读关于千层面的情节R在链接中论文的附录中,作者有很多代码来实现这些图。但这是一个 pdf,我无法复制到 RStudio(至少,我还没弄清楚如何)。有没有人把这些做成一个包,或者有没有人有更可用格式的代码?

4

3 回答 3

4

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

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

于 2013-07-23T20:50:32.767 回答
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') 

在此处输入图像描述

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

在此处输入图像描述

# 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()

在此处输入图像描述

于 2013-07-23T22:22:34.690 回答
0

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

https://github.com/swihart/lasagnar

于 2015-02-28T05:34:23.633 回答