在R中创建QQ图

时间:2014-04-05 19:43:51

标签: r plink quantile

我一直在努力在R中创建一个qq情节。我努力使用我的结果,所以我试图遵循“遗传病例对照研究中的基本统计分析,Clarke等人”的例子。

步骤5,a,iii)我用必填字段替换了路径和模型,如下所示:

data<-read.table("C:\Users\X\Desktop\BIOM3006\Alternate/data.assoc.logistic",header=TRUE);pdf("C:\Users\X\Desktop\BIOM3006\Alternate/pvalue.qq.plot.pdf");

obs<-−log10(sort(data[data$TEST=="ADD",]$P));exp<-−log10(c(1:length(obs))/(length(obs)+ 1));plot(exp, 

obs<-ylab="Observed(−logP)",xlab="Expected(−logP)",ylim=c(0,20),xlim=c(0,7)) lines(c(0,7),c(0,7),col=1,lwd=2);dev.off()

这是我收到的错误消息:

data<-read.table("C:\Users\Tom\Desktop\BIOM3006\Alternate/data.assoc.logistic",header=TRUE);pdf("C:\Users\Tom\Desktop\BIOM3006\Alternate/pvalue.qq.plot.pdf");
Error: '\U' used without hex digits in character string starting ""C:\U"

obs<-−log10(sort(data[data$TEST=="ADD",]$P));exp<-−log10(c(1:length(obs))/(length(obs)+ 1));plot(exp, 
Error in log10(sort(data[data$TEST == "ADD", ]$P)) : 
 non-numeric argument to mathematical function

In addition: Warning message:
In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'

obs<-ylab="Observed(−logP)",xlab="Expected(−logP)",ylim=c(0,20),xlim=c(0,7))
Error: unexpected ',' in "obs<-ylab="Observed(-logP)","

lines(c(0,7),c(0,7),col=1,lwd=2)
Error in plot.xy(xy.coords(x, y), type = type, ...) : 
plot.new has not been called yet

;dev.off()
Error: unexpected ';' in ";"

我仍然要掌握这个软件,所以如果我忽略了一些明显的东西,任何帮助都会受到赞赏和抱歉。 汤姆

3 个答案:

答案 0 :(得分:0)

我会说你非常接近,有一些格式问题需要一些小的修复(例如<--log之间没有空格)但是看起来很好但很难说没有可重复的例子。

data <- read.table("C:\Users\X\Desktop\BIOM3006\Alternate/data.assoc.logistic",header=TRUE)
pdf("C:\Users\X\Desktop\BIOM3006\Alternate/pvalue.qq.plot.pdf")
obs <- −log10(sort(data[data$TEST=="ADD",]$P))
exp<- −log10(c(1:length(obs))/(length(obs)+ 1))
plot(exp, obs, ylab="Observed(−logP)",xlab="Expected(−logP)",ylim=c(0,20),xlim=c(0,7)) lines(c(0,7),c(0,7),col=1,lwd=2))
dev.off()

答案 1 :(得分:0)

我同意上述内容,问题不在于您的代码本身,而在于"\U"

顺便说一句,我发布了一个更简单的脚本来创建QQ图,其中输出 plink 输出。

# If you call the script from bash it may include the name of your plink.qassoc file
args=(commandArgs(TRUE))
ARG = args[1]

# check libraries. It may download some from the Internet
if(!("methods" %in% rownames(installed.packages())))  
install.packages("methods")
library("methods")
if(!("ggplot2" %in% rownames(installed.packages())))  
install.packages("ggplot2")
library("ggplot2")

# Input data file (it is different for your file)
filename = paste ("../plink_files/", ARG, ".plink.qassoc.adjusted",sep="")
data = read.table (file = filename, header=T)

# Takes proability vector. 
PROB = data$UNADJ

# minus Log-P
logQQ = -log(data$QQ  ,10)
logP  = -log(PROB,10)

# QQ Plot
qqplot = ggplot (data = data, aes (x = logQQ, y = logP )) + geom_point(shape=1)
  qqplot = qqplot + xlab("Expected -logP values") + ylab("Observed -logP values")
  qqplot = qqplot + geom_abline (intercept = 0, slope = 1, color="red")
  qqplot = qqplot + ylim(0,max(logQQ,logP)) + xlim (0,max(logQQ,logP))

# Saving plot into a file
output = paste ("../results/", ARG, "_QQplot.jpg", sep="")
ggsave(output, plot = qqplot,width=6.47,height=4.67)

答案 2 :(得分:0)

我的工作原理:我只做了一些小修改。 看到 数据&LT; -read.table( “data.assoc”,首标= TRUE); PDF( “pvalue.qq.plot.pdf”);

OBS&LT; - 日志10(排序(数据[数据$ TEST == “ADD”,] $ P)); exp&lt; - log10(c(1:length(obs))/(length(obs)+ 1));

积(EXP,ylab = “看(-logP)”,xlab = “预期(-logP)”,ylim = C(0,20),XLIM = C(0,7))

线(C(0,7),C(0,7),山口= 1,LWD = 2);

dev.off()