无法在r

时间:2017-08-31 15:31:48

标签: r ggplot2

我在R中创建ggplot抖动图时遇到问题。我有一个数据框,aa,并希望使用每个基因名称(即AADAT)标记x轴。我希望y轴显示折叠变化值(来自aa的数值)。另外,我有两个列表,b1和b2,每个基因包含一定数量的TCGA样本及其倍数变化值。我想根据它们是属于b1还是b2来为抖动图中的所有倍数变化值着色。我该怎么做?

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"))

1 个答案:

答案 0 :(得分: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()