R)创建双标签的MDS图 [英] R) Create double-labeled MDS plot

查看:122
本文介绍了R)创建双标签的MDS图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对R完全陌生.
我有经过预处理和组合的表达式配置文件数据.看起来像这样("exp.txt")

I am totally new to R.
I have expression profile data which is preprocessed and combined. Looks like this ("exp.txt")

       STUDY_1_CANCER_1   STUDY_1_CON_1   STUDY_2_CANCER_1  STUDY_2_CANCER_2
P53    1.111              1.22             1.3               1.4
.....

我还创建了表型数据.看起来不错("pheno.txt")

Also, I created phenotype data. Looks lite this ("pheno.txt")

Sample               Disease        Study
STUDY_1_CANCER_1     Cancer         GSE1
STUDY_1_CON_1        Normal         GSE1
STUDY_2_CANCER_1     Cancer         GSE2
STUDY_2_CON_1        Normal         GSE2

在这里,我试图使用像这样的经典cmdscale命令制作MDS图.

Here, I tried to make MDS plot using classical cmdscale command like this.

data=read.table("exp.txt", row.names=1, header=T)
DATA=as.matrix(data)
pc=cor(DATA, method="p")
mds=cmdscale(as.dist(1-pc),2)
plot(mds)

我想创建一个带有彩色双标签(研究和疾病)的图形.我该怎么办?

I'd like to create plot like this figure with color double-labeling (Study and Disease). How should I do?

推荐答案

首先创建一个空图,然后添加具有指定颜色/形状的点.

First create an empty plot, then add the points with specified colors/shapes.

这是一个例子:

require(vegan)
data(dune)
data(dune.env)

mds <- cmdscale(vegdist(dune, method='bray'))


# set colors and shapes
cols = c('red', 'blue', 'black', 'steelblue')
shps = c(15, 16, 17)
# empty plot
plot(mds, type = 'n')
# add points
points(mds, col = cols[dune.env$Management], pch = shps[dune.env$Use])
# add legend
legend('topright', col=cols, legend=levels(dune.env$Management), pch = 16, cex = 0.7)
legend('bottomright', legend=levels(dune.env$Use), pch = shps, cex = 0.7)

请注意,因子在内部编码为整数,在这里很有用.

Note that factors are internally coded as integers, which is helpful here.

> levels(dune.env$Management)
[1] "BF" "HF" "NM" "SF"

如此

cols[dune.env$Management]

对于第一个因子水平,

将采用cols的第一项.不同形状的相似性.

will take the first entry of cols for the first factor levels. Similariy for the different shapes.

最后添加图例.当然,该情节仍然需要进行一些抛光,但这就是要走的路...

Finally add the legend. Of course this plot still needs some polishing, but thats the way to go...

顺便说一句:加文·辛普森(Gavin Simpson)的博客文章关于自定义排序图.

BTW: Gavin Simpson has a nice blogpost about customizing ordination plots.

这篇关于R)创建双标签的MDS图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆