Answers.Body: <ol>
  <li>I suppose in an idealized world you'd use something like <code>salmon</code> to get TPMs, which can account for differences in effective gene length by sample. However that's quite likely to be overkill.</li>
  <li>Not necessary, you're using a with-sample ratio, which wouldn't be changed by normalization.</li>
  </ol>
  
  <p>Here is a small example in R, assuming your matrix or data frame is named <code>m</code>:</p>
  
  <pre class="lang-r prettyprint-override"><code>first = which(row.names(m) == "ESCO1")
  second = which(row.names(m) == "ESCO2")
  plot(m[first,], m[second,])
  </code></pre>
  
  <p>or <code>cor(m[first, ], m[second,])</code>. You'll want a rank-based correlation.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T09:18:49.790Z
Answers.Text: When I did "cor(m[first, ], m[second,])" I see column names as both rows and columns and showing "NA" for all.
Answers.UserDisplayName: beginner
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T09:24:14.103Z
Answers.Text: Stop removing the column and row names.
Answers.UserDisplayName: Devon Ryan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T09:35:41.987Z
Answers.Text: don't know what's wrong. the dataframe "df" is with column names "gene", sample1, sample2, sample3 etc...I made the first column "gene" into rows. then I got the "ESCO1" into first and other into second. Then I did cor(df[first, ], df[second,]) and didn't work.
Answers.UserDisplayName: beginner
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T09:40:21.567Z
Answers.Text: "It didn't work" isn't ever a useful thing to write unless immediately followed by either the error message or problematic output you received. I presume your dataframe still has the `gene` column, which would need to be removed, or you need to put things through `c()` to get a proper vector.
Answers.UserDisplayName: Devon Ryan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T09:52:44.903Z
Answers.Text: @beginner when asking this sort of thing, you need to give us an example that reproduces your issue which we can run on our own machines. You are running some command with a wrong parameter, but since you don't show us the code you use, we can't help you find the mistake. Please see https://stackoverflow.com/help/mcve
Answers.UserDisplayName: terdon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T10:10:07.133Z
Answers.Text: @terdon sorry I misunderstood. but I tried in an other way and answered my own question. Please check that and let me know. thank you
Answers.UserDisplayName: beginner
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T10:10:53.380Z
Answers.Text: @DevonRyan I tried in the following way. Please check that. answered my own question. thank you
Answers.UserDisplayName: beginner
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T08:49:10.620Z
Answers.LastActivityDate: 2018-05-14T08:49:10.620Z
Answers.UserDisplayName: Devon Ryan
Answers.Body: <p>You can represent, and calculate, the correlations using psych:</p>
  
  <pre><code>library(psych)
  pairs.panels(df,df, 
               method = "pearson", # correlation method
               hist.col = "#00AFBB",
               density = TRUE,  # show density plots
               ellipses = TRUE,xlim=c(0,500),ylim=c(0,500))
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-23T18:56:59.353Z
Answers.LastActivityDate: 2018-06-25T07:56:12.137Z
Answers.LastEditDate: 2018-06-25T07:56:12.137Z
Answers.UserDisplayName: Zizogolu
Answers.Body: <p>I'm answering my own question. I tried this way.</p>
  
  <pre><code>df &lt;- read.csv("df.csv")
  
  Samples ESAM    ESCO1   ESCO2   ESD ESF1    ESM1
  Sample1 803     1594    274    6192 1356    398
  Sample2 338     1401    778    3502 1497    58
  Sample3 528      847    288    2013 1011    114
  Sample4 841      392    77     1573  372    582
  Sample5 712      611    204    1808  701    135
  
  df2 &lt;- data.frame(df[,-1],row.names = df[,1])
  
  cormat &lt;- round(cor(df2,use="pairwise.complete.obs"),2)
  head(cormat)
  
  library(ggcorrplot)
  pdf("eg.pdf")
  ggcorrplot(cormat,hc.order = TRUE,
             outline.col = "white",
             ggtheme = ggplot2::theme_gray,
             colors = c("#6D9EC1", "white", "#E46726"))
  dev.off()
  </code></pre>
  
  <p><a href="https://i.sstatic.net/4hmEq.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4hmEq.png" alt="enter image description here"></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T10:38:15.017Z
Answers.Text: This does not answer your own question, you ask for a plot with the correlation between 2 genes, but you show a correlation plot between all your genes...
Answers.UserDisplayName: benn
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T10:42:41.613Z
Answers.Text: yes, this shows correlation between all the genes but also shows the genes I'm interested in. I don't know how to plot for a specific genes so , I did this.
Answers.UserDisplayName: beginner
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T12:48:48.523Z
Answers.Text: Down vote from me, you ask for something else in your question (plot between two genes). Impossible to 'guess' what you are really meaning. Also from your answer it is not clear if you have to normalize or not.
Answers.UserDisplayName: benn
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T10:08:10.333Z
Answers.LastActivityDate: 2018-05-14T10:11:21.730Z
Answers.LastEditDate: 2018-05-14T10:11:21.730Z
Answers.UserDisplayName: beginner
Body: <p>I would like to plot the correlation between two specific genes in my data. I have a matrix with genes in rows and samples in columns, with read counts data. If I want to look at the correlation between 2 genes</p>
  
  <p>1) do I need to convert the counts to some other units?</p>
  
  <p>2) Is normalization needed?</p>
  
  <p>I currently have counts returned by <code>featureCounts</code>:</p>
  
  <pre><code>          Sample1  Sample2  Sample3  Sample4  Sample5
  
  ESAM         803    338       528       841      712
  ESCO1        1594   1401      847       392      611
  ESCO2         274   778       288       77       204
  ESD          6192   3502      2013      1573     1808
  ESF1         1356   1497      1011      372      701
  ESM1         398    58        114       582      135 
  </code></pre>
  
  <p>I tried this way:</p>
  
  <p>I transposed the above data making genes as columns and sample names as rows. I removed the rows. Lets say the genes as columns is in dataframe "df".</p>
  
  <pre><code>df.mat &lt;- cor(df)
  colnames(df.mat) &lt;- NULL
  rownames(df.mat) &lt;- NULL
  heatmap.2(df.mat, trace="none")
  </code></pre>
  
  <p>I have an error:</p>
  
  <pre><code>Error in .External.graphics(C_layout, num.rows, num.cols, mat, as.integer(num.figures),  : 
    invalid graphics state
  </code></pre>
  
  <p>I want to look at the correlation between ESCO1 and ESCO2. Can anyone tell me how to do that and plot with a small example.</p>
  
Tags: <rna-seq><r><gene><bioconductor>
Title: How to find correlation between two specific genes in same dataset?
ThreadText: # How to find correlation between two specific genes in same dataset?
  
  (Asked by: username_0 on 2018-05-14)
  
  I would like to plot the correlation between two specific genes in my data. I have a matrix with genes in rows and samples in columns, with read counts data. If I want to look at the correlation between 2 genes
  
  1) do I need to convert the counts to some other units?
  
  2) Is normalization needed?
  
  I currently have counts returned by `featureCounts`:
  
  ```
            Sample1  Sample2  Sample3  Sample4  Sample5
  
  ESAM         803    338       528       841      712
  ESCO1        1594   1401      847       392      611
  ESCO2         274   778       288       77       204
  ESD          6192   3502      2013      1573     1808
  ESF1         1356   1497      1011      372      701
  ESM1         398    58        114       582      135 
  
  ```
  
  I tried this way:
  
  I transposed the above data making genes as columns and sample names as rows. I removed the rows. Lets say the genes as columns is in dataframe "df".
  
  ```
  df.mat <- cor(df)
  colnames(df.mat) <- NULL
  rownames(df.mat) <- NULL
  heatmap.2(df.mat, trace="none")
  
  ```
  
  I have an error:
  
  ```
  Error in .External.graphics(C_layout, num.rows, num.cols, mat, as.integer(num.figures),  : 
    invalid graphics state
  
  ```
  
  I want to look at the correlation between ESCO1 and ESCO2. Can anyone tell me how to do that and plot with a small example.
  
  **Tags:** rna-seq, r, gene, bioconductor
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2018-05-14. Score: 3
  
  1. I suppose in an idealized world you'd use something like `salmon` to get TPMs, which can account for differences in effective gene length by sample. However that's quite likely to be overkill.
  2. Not necessary, you're using a with-sample ratio, which wouldn't be changed by normalization.
  
  Here is a small example in R, assuming your matrix or data frame is named `m`:
  
  ```r
  first = which(row.names(m) == "ESCO1")
  second = which(row.names(m) == "ESCO2")
  plot(m[first,], m[second,])
  
  ```
  
  or `cor(m[first, ], m[second,])`. You'll want a rank-based correlation.
  
  > **Comments:**
  > **username_0**: When I did "cor(m[first, ], m[second,])" I see column names as both rows and columns and showing "NA" for all.  
  > **username_1**: Stop removing the column and row names.  
  > **username_0**: don't know what's wrong. the dataframe "df" is with column names "gene", sample1, sample2, sample3 etc...I made the first column "gene" into rows. then I got the "ESCO1" into first and other into second. Then I did cor(df[first, ], df[second,]) and didn't work.  
  > **username_1**: "It didn't work" isn't ever a useful thing to write unless immediately followed by either the error message or problematic output you received. I presume your dataframe still has the `gene` column, which would need to be removed, or you need to put things through `c()` to get a proper vector.  
  > **username_2**: @username_0 when asking this sort of thing, you need to give us an example that reproduces your issue which we can run on our own machines. You are running some command with a wrong parameter, but since you don't show us the code you use, we can't help you find the mistake. Please see https://stackoverflow.com/help/mcve  
  > **username_0**: @username_2 sorry I misunderstood. but I tried in an other way and answered my own question. Please check that and let me know. thank you  
  > **username_0**: @username_1 I tried in the following way. Please check that. answered my own question. thank you  
  
  ---
  
  ### Answer by username_3 on 2018-06-23. Score: 0
  
  You can represent, and calculate, the correlations using psych:
  
  ```
  library(psych)
  pairs.panels(df,df, 
               method = "pearson", # correlation method
               hist.col = "#00AFBB",
               density = TRUE,  # show density plots
               ellipses = TRUE,xlim=c(0,500),ylim=c(0,500))
  
  ```
  
  
  ---
  
  ### Answer by username_0 on 2018-05-14. Score: 0
  
  I'm answering my own question. I tried this way.
  
  ```
  df <- read.csv("df.csv")
  
  Samples ESAM    ESCO1   ESCO2   ESD ESF1    ESM1
  Sample1 803     1594    274    6192 1356    398
  Sample2 338     1401    778    3502 1497    58
  Sample3 528      847    288    2013 1011    114
  Sample4 841      392    77     1573  372    582
  Sample5 712      611    204    1808  701    135
  
  df2 <- data.frame(df[,-1],row.names = df[,1])
  
  cormat <- round(cor(df2,use="pairwise.complete.obs"),2)
  head(cormat)
  
  library(ggcorrplot)
  pdf("eg.pdf")
  ggcorrplot(cormat,hc.order = TRUE,
             outline.col = "white",
             ggtheme = ggplot2::theme_gray,
             colors = c("#6D9EC1", "white", "#E46726"))
  dev.off()
  
  ```
  
  [![enter image description here](https://i.sstatic.net/4hmEq.png)](https://i.sstatic.net/4hmEq.png)
  
  > **Comments:**
  > **username_4**: This does not answer your own question, you ask for a plot with the correlation between 2 genes, but you show a correlation plot between all your genes...  
  > **username_0**: yes, this shows correlation between all the genes but also shows the genes I'm interested in. I don't know how to plot for a specific genes so , I did this.  
  > **username_4**: Down vote from me, you ask for something else in your question (plot between two genes). Impossible to 'guess' what you are really meaning. Also from your answer it is not clear if you have to normalize or not.  
  
  ---
  
  