Question: Correlation plot by correlation values in R
2
gravatar for A
11 months ago by
A3.6k
A3.6k wrote:

Hi,

You please imagine I have 23 differenrially expressed genes between tumour (26 samples) and normal (30 samples) tissues.

I have calculated the Pearson correlation values between the expression of these 23 differentially expressed genes in individual samples (56 samples) and the mean of expression of this gene in tumour (cor1) and normal (cor2) like below

> head(pred)
         cor1     cor2        scores    samples
cl1   0.8824150 0.7623499  0.06003256  tomour
cl1.1 0.7928945 0.6831890  0.05485271  tomour
cl1.2 0.8434347 0.7933102  0.02506226  tomour
cl1.3 0.7174795 0.5120342  0.10272268  tomour
cl1.4 0.6571185 0.6084326  0.02434294  tomour
cl1.5 0.5273702 0.6716480 -0.07213889  tomour
 > dim(pred)
[1] 56  4
  

And I have calculated a score like so

(cor1 – cor2)/2 (range: −1 to +1)

+1 says this is tomour sample and -1 says this is a normail sample

With such tables how I can represent a correlation plot like this picture? in this plot nicely samples were divided by scores and correlation

enter image description here

By this code

    b <- ggplot(pred1, aes(x = tomour, y =normal))

b + geom_point(aes(color =samples, shape = samples))+
  geom_smooth(aes(color = samples, fill = samples), method = "lm") +
  geom_rug(aes(color =samples)) +
  scale_color_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))+
  scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))

I have plotted

enter image description here

But this is not similar to what I want at all

rna-seq correlation R • 828 views
ADD COMMENTlink modified 11 months ago by Nicolas Rosewick8.5k • written 11 months ago by A3.6k

What have you tried? What is the ggplot code you have written so far?

Side note: Two ways to spell tumor are tumor or tumour. "Toumor" is not a valid word.

ADD REPLYlink modified 11 months ago • written 11 months ago by RamRS25k

Hi Thank you

I have found a function to calculate correlation, then I need to plot these correlations

ADD REPLYlink modified 11 months ago • written 11 months ago by A3.6k
3

Trying to "adjust" your data to a function found somewhere won't really work well. You have a good grasp on what you need, why not start at the basics and try plotting a correlation plot between two vectors of numbers, then expand step-by-step until you get to where you want? That's how you'll learn, not by trying to fit datasets into random code.

ADD REPLYlink written 11 months ago by RamRS25k

You al right Sorry for that

ADD REPLYlink modified 11 months ago • written 11 months ago by A3.6k
4

"I need to complete this soon" cannot be a reason for not learning. If you need to get it done soon, you can always hire an expert to do it for you. You have spent enough time and invested enough effort to take your time and get it done right.

ADD REPLYlink modified 11 months ago • written 11 months ago by RamRS25k
7
gravatar for Nicolas Rosewick
11 months ago by
Belgium, Brussels
Nicolas Rosewick8.5k wrote:

use geom_jitter from ggplot

library(ggplot2)
library(cowplot)

dat <- data.frame(
  sample=1:10,
  score=c(
    rnorm(n=40,mean = 0.7,sd=0.1),
    rnorm(n=40,mean=0,sd=0.1),
    rnorm(n=20,mean=-0.5,sd=0.1)),
  diagnoses=c(
    rep("ADC",40),
    rep("SCC",40),
    rep("Other NSCLC",20))
  )

head(dat)
#      sample     score diagnoses
#    1      1 0.5154322       ADC
#    2      2 0.7057089       ADC
#    3      3 0.6860727       ADC
#    4      4 0.5880083       ADC
#    5      5 0.7088662       ADC
#    6      6 0.6122866       ADC

# plot
ggplot(dat,aes(x=1,y=score,color=diagnoses))+
  geom_jitter(size=2) +
  geom_hline(yintercept = 0) +
  geom_hline(yintercept = 0.2,linetype=2) +
  geom_hline(yintercept = -0.2,linetype=2) +
  theme(axis.title.x=element_blank(), # remove x-axis label
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())

enter image description here

ADD COMMENTlink modified 11 months ago • written 11 months ago by Nicolas Rosewick8.5k

Thanks a lot

This is the same code I was looking for since last week

But I don't know what is going wrong with my data pasted in this post that my plot is too ugly

enter image description here

ADD REPLYlink written 11 months ago by A3.6k
1

Simply reduce the width size of your plot. And your score seems not so widely distributed (between -1 and 1) as the plot you showed in your post (more between -0.1 and 0.1)

ADD REPLYlink written 11 months ago by Nicolas Rosewick8.5k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 739 users visited in the last hour