<p>I'm not sure if nowadays matlab is still a good option for informatics. I would rather go for a R script to make a volcano plot. If you don't want to have fancy code but functional one, you can even make the foldchange calculations and log2 transformation in excel and just plot the log2 fold change in x axis and the -log10 transform of the p/q values on the y axis.
If you need it, I could provide one of my own scripts.</p>

<p><a href="https://i.sstatic.net/ymohs.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ymohs.png" alt="enter image description here"></a></p>

<p>Update: here is the actual script:</p>

<pre><code>#load data into the 'res' variable
res &lt;- read.table("genes.txt", header=TRUE)
head(res)

# Make a basic volcano plot with grey dots
with(res, plot(log2FoldChange, -log10(qvalue), pch=19, col="#4A4E4D", xlab="Log2 Fold Change", xlim=c(-8,8)))

# Add colored points: "indianred" if padj&lt;0.0001, orange of log2FC&gt;2, green if both)
with(subset(res, qvalue&lt;.0001 ), points(log2FoldChange, -log10(qvalue), pch=19, col="#17B090"))
with(subset(res, abs(log2FoldChange)&gt;2), points(log2FoldChange, -log10(qvalue), pch=19, col="#F89538"))
with(subset(res, qvalue&lt;.0001 &amp; abs(log2FoldChange)&gt;2), points(log2FoldChange, -log10(qvalue), pch=19, col="#FA6367"))
</code></pre>

CC BY-SA 3.0
2017-10-04T20:19:58.653Z
hey Erik, it would be really helpful for me if you could provide me the scripts you mentioned. I am a real noob in this, and am trying to figure out the best way to go about it
user1995
CC BY-SA 3.0
2017-10-04T20:03:50.670Z
2017-10-06T10:02:49.147Z
2017-10-06T10:02:49.147Z
Erik
<p>Is there a reason why you are doing this in MATLAB instead of R?</p>

<p>In R with the ggplot2 package you can make a volcano plot pretty easily using something like this (may be errors as it is off the top of my head and untested):</p>

<pre><code># load libraries
library(ggplot2)
library(data.table)

# create a dataframe/data.table of the data
a = c(1,2,3)
b = c(4.6, 2.7, 4.5)
c = c(0.05, 0.33, 0.45)
dt = data.table(A=a,B=b,pval=c)

# add column to calculate log2 fold change between a/b
dt[,log2Diff := (log2(A)-log2(B))]
# add column to transform pvalue to -log scale
dt[,logPval := -log10(pval)]

#make the plot
ggplot(dt, aes(x=log2Diff,y=logPval))+geom_point()
</code></pre>

CC BY-SA 3.0
2017-10-04T18:13:23.590Z
2017-10-04T18:13:23.590Z
Reilstein
<p>so while I am not so familiar with MATLAB, in the definition of the volcano plot it specifies that <em>PValues</em> is supposed to be a column vector or a DataMatrix object. Your <em>c</em> vector is a row vector, and this confuses MATLAB.</p>

CC BY-SA 3.0
2017-10-04T05:53:01.870Z
2017-10-04T05:53:01.870Z
galicae
<p>I am a complete newbie to MATLAB and the first task I have is to create a volcano plot. I have been using <a href="https://www.mathworks.com/help/bioinfo/ref/mavolcanoplot.html" rel="nofollow noreferrer">this link</a> to understand about it and get started.</p>

<p>I tried to run it on dummy values - </p>

<pre><code>a=[1 2 3]

b=[4.6 2.7 4.5]

c=[0.05 0.33 0.45]
</code></pre>

<p>And then I ran - </p>

<pre><code>SigStructure = mavolcanoplot(a, b, c)
</code></pre>

<p>My understanding is that <code>a</code> represents the gene expression values for condition 1, <code>b</code> for condition 2, and <code>c</code> is the list of p-values for the 3 data points in <code>a</code> and <code>b</code>.</p>

<p>However running this code gives me the error - </p>

<pre><code>Index exceeds matrix dimensions.

Error in mavolcanoplot (line 127)
appdata.effect = X(paramStruct.goodVals) - Y(paramStruct.goodVals);

Error in volc (line 4)
SigStructure = mavolcanoplot(a, b, c)
</code></pre>

<p>Can anyone explain where I am going wrong?</p>

CC BY-SA 3.0
2017-09-29T06:40:00.803Z
Cross-posted [on biostars](https://www.biostars.org/p/275322/).
Devon Ryan
<differential-expression><matlab>
Error in creating a volcano plot in MATLAB
# Error in creating a volcano plot in MATLAB

(Asked by: username_0 on 2017-09-29)

I am a complete newbie to MATLAB and the first task I have is to create a volcano plot. I have been using this link to understand about it and get started.
I tried to run it on dummy values - 
a=[1 2 3]

b=[4.6 2.7 4.5]

c=[0.05 0.33 0.45]

And then I ran - 
SigStructure = mavolcanoplot(a, b, c)

My understanding is that a represents the gene expression values for condition 1, b for condition 2, and c is the list of p-values for the 3 data points in a and b.
However running this code gives me the error - 
Index exceeds matrix dimensions.

Error in mavolcanoplot (line 127)
appdata.effect = X(paramStruct.goodVals) - Y(paramStruct.goodVals);

Error in volc (line 4)
SigStructure = mavolcanoplot(a, b, c)

Can anyone explain where I am going wrong?

**Tags:** differential-expression, matlab
> **Comments:**
> **username_1**: Cross-posted [on biostars](https://www.biostars.org/p/275322/).  

---

## 3 answers

### Answer by username_2 on 2017-10-04. Score: 3 | Accepted answer

I'm not sure if nowadays matlab is still a good option for informatics. I would rather go for a R script to make a volcano plot. If you don't want to have fancy code but functional one, you can even make the foldchange calculations and log2 transformation in excel and just plot the log2 fold change in x axis and the -log10 transform of the p/q values on the y axis.
If you need it, I could provide one of my own scripts.

Update: here is the actual script:
#load data into the 'res' variable
res <- read.table("genes.txt", header=TRUE)
head(res)

# Make a basic volcano plot with grey dots
with(res, plot(log2FoldChange, -log10(qvalue), pch=19, col="#4A4E4D", xlab="Log2 Fold Change", xlim=c(-8,8)))

# Add colored points: "indianred" if padj<0.0001, orange of log2FC>2, green if both)
with(subset(res, qvalue<.0001 ), points(log2FoldChange, -log10(qvalue), pch=19, col="#17B090"))
with(subset(res, abs(log2FoldChange)>2), points(log2FoldChange, -log10(qvalue), pch=19, col="#F89538"))
with(subset(res, qvalue<.0001 & abs(log2FoldChange)>2), points(log2FoldChange, -log10(qvalue), pch=19, col="#FA6367"))

> **Comments:**
> **username_0**: hey Erik, it would be really helpful for me if you could provide me the scripts you mentioned. I am a real noob in this, and am trying to figure out the best way to go about it  

---

### Answer by username_3 on 2017-10-04. Score: 2

Is there a reason why you are doing this in MATLAB instead of R?
In R with the ggplot2 package you can make a volcano plot pretty easily using something like this (may be errors as it is off the top of my head and untested):
# load libraries
library(ggplot2)
library(data.table)

# create a dataframe/data.table of the data
a = c(1,2,3)
b = c(4.6, 2.7, 4.5)
c = c(0.05, 0.33, 0.45)
dt = data.table(A=a,B=b,pval=c)

# add column to calculate log2 fold change between a/b
dt[,log2Diff := (log2(A)-log2(B))]
# add column to transform pvalue to -log scale
dt[,logPval := -log10(pval)]

#make the plot
ggplot(dt, aes(x=log2Diff,y=logPval))+geom_point()


---

### Answer by username_4 on 2017-10-04. Score: 2

so while I am not so familiar with MATLAB, in the definition of the volcano plot it specifies that *PValues* is supposed to be a column vector or a DataMatrix object. Your *c* vector is a row vector, and this confuses MATLAB.


---

