0

I am having trouble creating a ggplot jitter plot in R. I have a data frame, aa, and want to make the x-axis to be labelled with each gene name (i.e. AADAT). I want the y-axis to display fold-change values (the numeric values from aa). Also, I have two lists, b1 and b2, containing a certain number of the TCGA samples for each gene and their fold-change values. I want to color all the fold change values from the jitter plot based on whether they belong to b1 or b2. How would I do this?

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"))
merryberry
  • 91
  • 1
  • 9
  • Did you try any ggplot code at all; if so, share that as well. Also, please share your data in a more [reproducible format](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) such as a `dput()` so it's easier to help you. – MrFlick Aug 31 '17 at 15:35
  • what have you tried, and can you dput your data do we can easily use it? – Preston Aug 31 '17 at 15:35
  • this is the code I tried( I know it's wrong, I'm just unsure of how to accurately create my plot): – merryberry Aug 31 '17 at 15:40
  • ggplot(aa, aes(row.names(aa), aa)) + geom_jitter(aes(color = v1)) – merryberry Aug 31 '17 at 15:41
  • I just edited the code and provided dput values – merryberry Aug 31 '17 at 15:43

1 Answers1

1

Are you looking for something like this?

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()
Z.Lin
  • 28,055
  • 6
  • 54
  • 94