2017-08-31 57 views
0

我在創建r中的ggplot jitter圖時遇到了困難。我有一個數據框aa,並且想要使x軸標記每個基因名稱(即AADAT) 。我希望Y軸顯示摺疊值(來自aa的數值)。此外,我有兩個列表,b1和b2,包含每個基因的一定數量的TCGA樣本及其折變值。我想根據抖動情節屬於b1還是b2來對所有摺疊變化值進行着色。我將如何做到這一點?無法在r中創建ggplot jitter plot

dput(AA):

structure(list(TCGA.BC.A10Q = c(2.54076411223946, 1.11243159235432, 
-8.07819965644818), TCGA.DD.A1EB = c(0.437216525767862, 0.461169651797969, 
-1.35226172820141), TCGA.DD.A1EG = c(2.19320501695823, 1.27412886320315, 
-3.46331855085169), TCGA.DD.A1EH = c(3.26575582726209, 1.80298461724572, 
-4.4298527877724), TCGA.DD.A1EI = c(0.606030095793745, -0.0475743042500462, 
-3.03789531487311), TCGA.DD.A3A6 = c(2.92707172081351, 1.0710641387449, 
-4.67961035825927), TCGA.DD.A3A8 = c(0.679951440435414, 0.433630069956858, 
-2.02366124071563), TCGA.ES.A2HT = c(-0.0812955357950507, 1.76935812455138, 
0.236573023675848), TCGA.FV.A23B = c(2.29637640282035, 0.364439713535423, 
-1.94003185763597), TCGA.FV.A3I0 = c(3.196518439057, 1.39220627799838, 
-7.67942521158398), TCGA.FV.A3R2 = c(0.859594276372461, 1.0282030128145, 
0.131890257248429)), .Names = c("TCGA.BC.A10Q", "TCGA.DD.A1EB", 
"TCGA.DD.A1EG", "TCGA.DD.A1EH", "TCGA.DD.A1EI", "TCGA.DD.A3A6", 
"TCGA.DD.A3A8", "TCGA.ES.A2HT", "TCGA.FV.A23B", "TCGA.FV.A3I0", 
"TCGA.FV.A3R2"), row.names = c("ABCC10", "ACBD6", "ACSL1"), class = "data.frame") 

dput(B1):

structure(list(ABCC10 = structure(c(2.19320501695823, 0.859594276372461, 
3.196518439057, 3.26575582726209, 2.29637640282035), .Names = c("TCGA.DD.A1EG", 
"TCGA.FV.A3R2", "TCGA.FV.A3I0", "TCGA.DD.A1EH", "TCGA.FV.A23B" 
)), ACBD6 = structure(c(1.80298461724572, 0.433630069956858, 
1.76935812455138, 1.27412886320315, 0.461169651797969), .Names = c("TCGA.DD.A1EH", 
"TCGA.DD.A3A8", "TCGA.ES.A2HT", "TCGA.DD.A1EG", "TCGA.DD.A1EB" 
)), ACSL1 = structure(c(-1.94003185763597, -3.46331855085169, 
-3.03789531487311, -4.4298527877724), .Names = c("TCGA.FV.A23B", 
"TCGA.DD.A1EG", "TCGA.DD.A1EI", "TCGA.DD.A1EH"))), .Names = c("ABCC10", 
"ACBD6", "ACSL1")) 

dput(B2):

structure(list(ABCC10 = structure(c(2.54076411223946, 0.437216525767862, 
0.606030095793745, 2.92707172081351, 0.679951440435414, -0.0812955357950507 
), .Names = c("TCGA.BC.A10Q", "TCGA.DD.A1EB", "TCGA.DD.A1EI", 
"TCGA.DD.A3A6", "TCGA.DD.A3A8", "TCGA.ES.A2HT")), ACBD6 = structure(c(1.11243159235432, 
-0.0475743042500462, 1.0710641387449, 0.364439713535423, 1.39220627799838, 
1.0282030128145), .Names = c("TCGA.BC.A10Q", "TCGA.DD.A1EI", 
"TCGA.DD.A3A6", "TCGA.FV.A23B", "TCGA.FV.A3I0", "TCGA.FV.A3R2" 
)), ACSL1 = structure(c(-8.07819965644818, -1.35226172820141, 
-4.67961035825927, -2.02366124071563, 0.236573023675848, -7.67942521158398, 
0.131890257248429), .Names = c("TCGA.BC.A10Q", "TCGA.DD.A1EB", 
"TCGA.DD.A3A6", "TCGA.DD.A3A8", "TCGA.ES.A2HT", "TCGA.FV.A3I0", 
"TCGA.FV.A3R2"))), .Names = c("ABCC10", "ACBD6", "ACSL1")) 
+0

你有沒有嘗試任何ggplot代碼在所有;如果是的話,也分享一下。此外,請分享您的數據在更多[可重現格式](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example),如'dput()'所以幫助你更容易。 – MrFlick

+0

你有什麼試過的,你可以輸入你的數據嗎?我們可以輕鬆使用它嗎? – User632716

+0

這是我嘗試的代碼(我知道這是錯誤的,我只是不確定如何準確地創建我的情節): – merryberry

回答

1

您正在尋找這樣的事情?

ggplot

library(dplyr); library(tidyr); library(ggplot2) 

# convert aa from wide to long format 
aa$gene <- rownames(aa) 
aa <- aa %>% 
    gather(TCGA, fold.change, -gene) 

# convert lookup lists into data frame for matching 
match.table <- rbind(stack(b1) %>% mutate(source = "b1"), 
        stack(b2) %>% mutate(source = "b2")) 

aa <- left_join(aa, match.table, 
       by = c("gene" = "ind", "fold.change" = "values")) 

ggplot(aa, 
     aes(x = gene, y = fold.change, col = source)) + 
    geom_jitter() + 
    theme_light()