help for volcano plot

869 views
Skip to first unread message

Chen Qian

unread,
Apr 17, 2014, 10:54:04 AM4/17/14
to ggp...@googlegroups.com
Hi All,

I am new to R. Right now I am trying to plot a simple volcano plot, but got some error that I cannot fix. 
require(ggplot2)

Volcano_data$threshold = as.factor(abs(Volcano_data$logFC) > 2 & Volcano_data$P.Value < 0.05)
 
##Construct the plot object
g = ggplot(data=gene_list, aes(x=logFC, y=-log10(P.Value), colour=threshold)) +
  geom_point(alpha=0.4, size=1.75) +
  theme(legend.position = "none") +
  xlim(c(-5, 5)) + ylim(c(0, 5)) +
  xlab("log2 fold change") + ylab("-log10 p-value")
g
The error is: Error in eval(expr, envir, enclos) : object 'threshold' not found. Anybody can help me with it? Thanks a lot. ---Chen






Julio Rojas

unread,
Apr 17, 2014, 1:23:13 PM4/17/14
to Chen Qian, ggp...@googlegroups.com
Dear Qian,

It seems that you are using 

data=gene_list

instead of

data=Volcano_data

"Threshold" is defined in the second one.

Hope it helps.
-------------------------------------------------
Julio Rojas
jcred...@gmail.com


--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chen Qian

unread,
Apr 17, 2014, 3:04:54 PM4/17/14
to Julio Rojas, ggp...@googlegroups.com
Thank you all for the reply. I correct the error about volcano_data, but it still did not work. Attached is the file I am working with. 

volcano_data = read.table("Volcano plot2.txt", header = T, sep = "")
require(ggplot2)
##Highlight genes that have an absolute fold change > 2 and a p-value < Bonferroni cut-off
volcano_data$threshold = as.factor(abs(volcano_data$Log2) > 1 & volcano_datat$Logo > 1.2)

##Construct the plot object
g=ggplot(data=volcano_data, aes(x=Log2, y=Logo, colour= factor(threshold)) +
  geom_point(alpha=0.4, size=1.75) +
  theme(legend.position = "none") +
  xlim(c(-4, 4)) + ylim(c(0, 5)) +
  xlab("log2 fold change") + ylab("-log10 p-value")
g  
Volcano plot2.txt

Dennis Murphy

unread,
Apr 17, 2014, 3:23:01 PM4/17/14
to Chen Qian, ggplot2
You had a couple of typos in your code. Here is a modified version
that adds some color saturation, changes the default theme to B-W and
modifies the axis labels to subscript the log bases. Delete the
theme_bw() line to get the original theme back, and remove the
scale_colour_manual() line to retrieve the original color set.

volcano_data = read.table("Volcano plot2.txt", header = TRUE, sep = "")
volcano_data <- transform(volcano_data,
threshold = as.factor(abs(volcano_data$Log2) > 1 & volcano_data$Logo > 1.2)

##Construct the plot object
g=ggplot(data=volcano_data, aes(x=Log2, y=Logo, colour= threshold)) +
theme_bw() +
geom_point(alpha=0.4, size=1.75) +
theme(legend.position = "none") +
xlim(c(-4, 4)) + ylim(c(0, 5)) +
xlab(expression(log[2]~"fold change")) +
ylab(expression(-log[10]~"p-value")) +
scale_colour_manual(values = c("firebrick", "navy"))
g

Dennis
Reply all
Reply to author
Forward
0 new messages