[英]How to make a scatterplot showing correlation between a single gene vs multiple genes?
我有一個矩陣,樣本為行,Genes為具有基因表達值(RPKM)的列。
以下是示例數據。 原始數據有800多個樣本。
LINP1 EGFR RB1 TP53 CDKN2A MYC
Sample1 0.02 0.038798682 0.1423662 2.778587067 0.471403939 18.93687655
Sample2 0 0.059227225 0.208765213 0.818810739 0.353671882 1.379027685
Sample3 0 0.052116384 0.230437735 2.535040249 0.504061015 9.773089223
Sample4 0.06 0.199264618 0.261100548 2.516963635 0.63659138 11.01441624
Sample5 0 0.123521916 0.273330986 2.751309388 0.623572499 34.0563519
Sample6 0 0.128767634 0.263491811 2.882878373 0.359322715 13.02402045
Sample7 0 0.080097356 0.234511372 3.568192768 0.386217698 9.068928569
Sample8 0 0.017421323 0.247775683 5.109428797 0.068760572 15.7490551
Sample9 0 2.10281137 0.401582013 8.202902242 0.140596724 60.25989178
為了制作顯示兩個基因之間相關性的散點圖,我使用了ggscatter
ggscatter(A2, x = "LINP1", y = "EGFR",
add = "reg.line", conf.int = FALSE,
cor.coef = TRUE, cor.method = "pearson",
xlab = "LINP1", ylab = "EGFR", xscale="log2", yscale="log2")
散點圖看起來像這樣
我想制作一個像這樣的散點圖
圖2g在本研究論文中 。 其中LINP1表達在單個圖中顯示針對所有其他基因。 是否可以使用任何代碼?
當您進行皮爾森相關時,結果與您進行散點圖並從回歸模型繪制擬合線相同,該回歸模型可以在ggplot2::geom_smooth()
中與基因的散點圖一起完成。
編輯:更新為根據OP的注釋在兩個比例上使用log2()轉換。 請注意,進行轉換時,有時可能會獲得無效值。 您的數據為0
s,因此log2()轉換返回-Inf
:
library(tidyr)
library(ggplot2)
df <- read.table(text = "
LINP1 EGFR RB1 TP53 CDKN2A MYC
Sample1 0.02 0.038798682 0.1423662 2.778587067 0.471403939 18.93687655
Sample2 0 0.059227225 0.208765213 0.818810739 0.353671882 1.379027685
Sample3 0 0.052116384 0.230437735 2.535040249 0.504061015 9.773089223
Sample4 0.06 0.199264618 0.261100548 2.516963635 0.63659138 11.01441624
Sample5 0 0.123521916 0.273330986 2.751309388 0.623572499 34.0563519
Sample6 0 0.128767634 0.263491811 2.882878373 0.359322715 13.02402045
Sample7 0 0.080097356 0.234511372 3.568192768 0.386217698 9.068928569
Sample8 0 0.017421323 0.247775683 5.109428797 0.068760572 15.7490551
Sample9 0 2.10281137 0.401582013 8.202902242 0.140596724 60.25989178", header = TRUE)
df %>%
gather(key = variable, value = values, EGFR:MYC) %>%
ggplot(aes(LINP1, values)) +
geom_point() +
facet_grid(. ~ variable, scales = "free_x") +
geom_smooth(method = "lm", se = FALSE) +
scale_y_continuous(trans = "log2") +
scale_x_continuous(trans = "log2")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.