Search code examples
rdataframeggplot2correlationscatter-plot

how to plot scatter plot for two different dataset in R


I want to ask how to plot scatter plot for correlation value obtained from two different datasets.

So I did analysis between predicted and actual expression before and after doing PCA analysis. I see that correlation for some gene is improved after removal of noise by doing PCA. I want to plot these values to show that correlation is improved before and after analysis. Basically draw a 45 angle line and show rho after analysis being above the rho before analysis for the 10 gene. Is there anyway to this

My dataset looks like:

dput(data)
structure(list(rho_before = c(0.4307495, 0.5960163, 0.5493751, 
0.490663, 0.5255558, 0.4066614, 0.3735131, 0.4254657, 0.3644662, 
0.1835266), rho_pca = c(0.4891171, 0.5352205, 0.6741458, 0.607399, 
0.6842696, 0.4207939, 0.4573174, 0.6284339, 0.7400641, 0.3667239
)), class = "data.frame", row.names = c("gene1", "gene2", "gene3", 
"gene4", "gene5", "gene6", "gene7", "gene8", "gene9", "gene10"
))

Thank you.


Solution

  • To plot the before and after values for the same gene against each other to demonstrate that the PCA values are consistently higher than the "before" values (ie, if values were equal they would fall on the 45 degree line, and if "before" was better it would fall on the below the line)

    plot(data, xlim = 0:1, ylim = 0:1, pch = 21, bg = "maroon",
         ylab = expression(rho[pca]), xlab = expression(rho[before]))
    abline(0, 1)
    

    enter image description here