1

I have been trying to create a qq plot in R. I struggled using my results so I have tried to follow the example from "Basic statistical analysis in genetic case-control studies, Clarke et al.)

Step 5, a, iii) I have replaced the path to's and models with the required field and appears as follows:

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

This is the error message that I'm getting:

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 ";"

I'm still getting to grips with this software so any help would be appreciated and sorry if I have overlooked something glaringly obvious. Tom

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
user3253698
  • 11
  • 1
  • 2
  • I would say re-check the filepath that you are using to load the data - looks like you have slashes going in both directions – Stedy Apr 05 '14 at 19:50
  • Stedy is probably right. Use the output of `.Platform$file.sep` to see how to separate the elements of your path. – alexis_laz Apr 05 '14 at 20:00
  • 1
    This has nothing to do with Q-Q plots. Backslash in R is used to escape the following character. The "\U" starts the definition of unicode character, so it expects a hex value after the "\U". Try typing, for example, "\U03A3" at the R console. File paths use forward slash (in Windows too). See [this post](http://stackoverflow.com/questions/8425409/file-path-issues-in-r-using-windows-hex-digits-in-character-string-error). – jlhoward Apr 05 '14 at 22:23

3 Answers3

0

I would say you are pretty close, there were some formatting issues that need some minor fixes (such as no whitespace between <- and -log) but otherwise it looks ok though difficult to tell with no reproducible example.

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()
Stedy
  • 7,359
  • 14
  • 57
  • 77
0

I agree with the above coments, the problem is not in your piece of code itself, but in the "\U".

By the way, I post a simpler script for creating QQ plots taking plink output as in your example.

# 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)
elcortegano
  • 2,444
  • 11
  • 40
  • 58
0

fOR ME IT WORKS: I just do minor modifications. SEE data<-read.table("data.assoc",header=TRUE); pdf("pvalue.qq.plot.pdf");

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

plot(exp,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()

forever
  • 139
  • 1
  • 2
  • 8