我正在读取这样的文件:
genes<-read.table("goi.txt",header=TRUE, row.names=1)
control<-log2(1+(genes[,1]))
experiment<-log2(1+(genes[,2]))
并将它们绘制为一个简单的散点图ggplot
:
ggplot(genes, aes(control, experiment)) +
xlim(0, 20) +
ylim(0, 20) +
geom_text(aes(control, experiment, label=row.names(genes)),size=3)
但是,这些点被错误地放置在我的绘图上(参见附图)
这是我的数据:
control expt
gfi1 0.189634 3.16574
Ripply3 13.752000 34.40630
atonal 2.527670 4.97132
sox2 16.584300 42.73240
tbx15 0.878446 3.13560
hes8 0.830370 8.17272
Tlx1 1.349330 7.33417
pou4f1 3.763400 9.44845
pou3f2 0.444326 2.92796
neurog1 13.943800 24.83100
sox3 17.275700 26.49240
isl2 3.841100 10.08640
如您所见,“ Ripply3”在图表上显然处于错误的位置!
我是不是在做一些愚蠢的事情?
由aes()
所使用的函数ggplot
首先在您通过提供的数据框中进行查找data = genes
。这就是为什么您可以(并且应该)仅通过裸列名称(如control
; )指定变量的原因 ggplot
会自动知道在哪里可以找到数据。
但是R的范围界定系统是这样的:如果在当前环境中未找到该名称的任何内容,则R将在父环境中进行查找,依此类推,直到到达全局环境,直到它找到该名称的东西为止。
因此,在数据框内aes(control, experiment)
查找名为control
和的变量。它会找到原始的,未转换的变量,但是当然中没有变量。因此,它一直沿环境链向上移动,直到遇到全局环境为止,在全局环境中您定义了隔离变量并使用了该变量。experiment
genes
control
experiment
genes
experiment
您打算做更多这样的事情:
genes$controlLog <- log2(1+(genes[,1]))
genese$exptLog <- log2(1+(genes[,2]))
其次是:
ggplot(genes, aes(controlLog, exptLog)) +
xlim(0, 20) +
ylim(0, 20) +
geom_text(aes(controlLog, exptLog, label=row.names(genes)),size=3)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句