I have been trying to add two legends to this plot:
I want to add geom_point(color = all_counts.dir_s2.results$genecolor)
as an additional legend.
plot_dir_s2 <-
all_counts.dir_s2.results %>%
as.data.frame() %>%
ggplot(aes(log2(baseMean), log2FoldChange)) +
geom_point(aes(color = pvalue < 0.05), cex = 0.1, position=position_jitter(w=0.01,h=0.1)) +
geom_point(color = all_counts.dir_s2.results$genecolor) +
labs(title = "RPS2 Torin Treated vs Untreated PNAS Genes", x = "log2Expression") +
ylim(-4, 4)
NULL
So I'm looking to make something like this:
Would I use scale_color_manual
to manually add these in?
scale_color_manual(values = c("padj > 0.05" = "red",
"padj < 0.05" = "teal",
"PNAS genes" = "purple")
Data here:
all_counts.dir_s2.results <-
structure(
list(
EnsGeneID = c(
"ENSG00000109971",
"ENSG00000285080",
"ENSG00000105889",
"ENSG00000008988",
"ENSG00000156508",
"ENSG00000167658",
"ENSG00000106554",
"ENSG00000109475",
"ENSG00000111640",
"ENSG00000258077",
"ENSG00000005022",
"ENSG00000026025",
"ENSG00000163931",
"ENSG00000220842",
"ENSG00000070756",
"ENSG00000065978",
"ENSG00000228929",
"ENSG00000180879",
"ENSG00000226360",
"ENSG00000244245",
"ENSG00000232712",
"ENSG00000204628",
"ENSG00000186468",
"ENSG00000233913",
"ENSG00000229659",
"ENSG00000219274",
"ENSG00000149273",
"ENSG00000147403",
"ENSG00000137154",
"ENSG00000203907",
"ENSG00000198755",
"ENSG00000213315",
"ENSG00000228887",
"ENSG00000197360",
"ENSG00000221983",
"ENSG00000234742",
"ENSG00000178464",
"ENSG00000240738",
"ENSG00000224861",
"ENSG00000228205",
"ENSG00000166441",
"ENSG00000123349",
"ENSG00000212802",
"ENSG00000187109",
"ENSG00000218426",
"ENSG00000129515",
"ENSG00000235175",
"ENSG00000110700",
"ENSG00000230629",
"ENSG00000166689",
"ENSG00000133112",
"ENSG00000232573",
"ENSG00000227525",
"ENSG00000145425",
"ENSG00000065150",
"ENSG00000122406",
"ENSG00000239559",
"ENSG00000242299",
"ENSG00000170889",
"ENSG00000105372",
"ENSG00000184831",
"ENSG00000096384",
"ENSG00000139239",
"ENSG00000198918",
"ENSG00000220749",
"ENSG00000225200",
"ENSG00000237550",
"ENSG00000196511",
"ENSG00000226084",
"ENSG00000075415",
"ENSG00000213280",
"ENSG00000214748",
"ENSG00000137970",
"ENSG00000051523",
"ENSG00000236844",
"ENSG00000228502",
"ENSG00000104722",
"ENSG00000174748",
"ENSG00000178741",
"ENSG00000225912",
"ENSG00000220370",
"ENSG00000185641",
"ENSG00000227615",
"ENSG00000198431",
"ENSG00000237049",
"ENSG00000146677",
"ENSG00000243829",
"ENSG00000224631",
"ENSG00000260898",
"ENSG00000243199",
"ENSG00000114391",
"ENSG00000232472",
"ENSG00000232176",
"ENSG00000142937",
"ENSG00000181524",
"ENSG00000236552",
"ENSG00000235552",
"ENSG00000125691",
"ENSG00000223676",
"ENSG00000241494"
),
baseMean = c(
1095.31857607063,
592.445494739157,
1177.80855319897,
654.762885017899,
541.069027423406,
3385.31917292566,
2346.6625765827,
1900.17143907793,
9214.50635932529,
225.760894371447,
582.702263829148,
1269.66479230146,
1022.67773974919,
499.656500065798,
2418.48464257135,
998.530007694609,
1074.9540137383,
1720.49852346652,
1052.38625395776,
347.013381196818,
152.145329613279,
6509.31081914136,
602.185990124399,
591.274484606163,
262.459320898851,
152.253689386927,
1803.54155562342,
1687.54874792706,
3414.814032345,
668.569284831465,
1321.53071412171,
416.675934786263,
506.203474547914,
91.7960148395533,
1564.81496127497,
246.867404412426,
184.648167904095,
340.291172688643,
193.73195681553,
165.921885978623,
845.238238207963,
314.856420444992,
684.508465885965,
1175.59500763978,
208.03565295281,
423.619431032168,
130.978685412339,
698.054374521658,
359.260523548016,
292.541834401905,
408.978425690628,
1864.02534562533,
224.041002260477,
212.297994406831,
338.551602588589,
2634.40359801874,
262.407724588084,
828.081698719403,
1365.56267740348,
2302.46106349641,
384.682787669164,
9413.64738807171,
812.173464451936,
255.120920916547,
97.5199433617571,
782.971125416077,
137.146562287411,
92.5757279278087,
157.667852340176,
595.49169928228,
387.222338554843,
424.12061222847,
475.366012597284,
1017.48774062861,
385.392011521195,
189.366195768179,
587.097225197315,
1766.98793458201,
743.836940934617,
114.338914591437,
112.882471243503,
1308.8697110712,
564.737601999289,
858.32478049716,
50.4799242404189,
585.1960147226,
358.486720273333,
564.888713645347,
21.4974919105639,
843.804617919398,
1020.3350422589,
429.06380723344,
265.954792068853,
3059.5537229438,
401.189242814625,
1017.43141828211,
2266.80553131293,
2220.45893040228,
52.877317604412,
83.705572068192
),
log2FoldChange = c(
-2.0183653034074,-2.07101347509777,
-2.20311149392739,
-1.73134369022066,
-1.86189372785931,-1.7222920979343,
-1.58174836615284,
-1.55463855546746,
-1.58894875737464,-1.93714542684058,
-1.61698688058756,
-1.54229924438531,
-1.35361317971803,-1.67070381160127,
-1.2988292716825,
-1.36536010862324,
-1.40370428515576,-1.33795205375909,
-1.31656369417928,
-1.79401615862215,
-1.9734309805019,-1.2758268423695,
-1.40634659267066,
-1.38656230355066,
-1.63423748311413,-2.04669104755808,
-1.31366149061346,
-1.34310199306866,
-1.10769678811283,-1.3049370056618,
-1.11719488676431,
-1.372098937987,
-1.26266990702409,-2.16638812406429,
-1.20935918804272,
-1.48160015601683,
-1.68353354818499,-1.31962005314326,
-1.4756089749056,
-1.6598052015808,
-1.21719622822649,-1.30693509493117,
-1.24169591343418,
-1.02619910073139,
-1.55236053768099,-1.21519830751149,
-1.89677667206551,
-1.21230124126626,
-1.29326969250991,-1.26582179766441,
-1.22216982890919,
-1.09394036287155,
-1.36715544338926,-1.45950706616776,
-1.22329833446237,
-0.990183714941196,
-1.28110328655418,-1.11865028054913,
-1.14329357304439,
-1.14848611565117,
-1.20155919925426,-0.941667790711213,
-1.06145064849424,
-1.27890379060449,
-1.76318920759731,-1.02158388278365,
-1.51780614286352,
-1.87261391459523,
-1.48882724039241,-1.05479533608263,
-1.23283762446814,
-1.16251688968316,
-1.1283771329761,-1.03589083325477,
-1.20517491245122,
-2.73812031011786,
-1.07921290542485,-1.11643907902893,
-1.04249645226895,
-1.74811951713493,
-1.59950682107044,-1.0513227658533,
-1.0209609392492,
-0.956533826034593,
-2.17345914920422,-1.00986691348105,
-1.24042518500277,
-1.01608286240974,
-7.80331238832679,-0.920146611262127,
-0.929016321108488,
-1.09828795446757,
-1.13165337360373,-0.859363504230098,
-1.10306509825187,
-0.977731739606374,
-0.970556949127596,-0.960693084249075,
-2.01832238081385,
-1.71974919718578
),
lfcSE = c(
0.185690457540347,
0.197587691894742,
0.216823099095797,
0.194030022145317,
0.215109146062061,
0.203267932075425,
0.187353373767619,
0.188746248799253,
0.193024950572106,
0.251990908283876,
0.210635033935669,
0.201533186952436,
0.178205687341961,
0.220020839056972,
0.171916316053662,
0.180816253942394,
0.187364875633129,
0.181676592919805,
0.178986896136368,
0.244230993901665,
0.270657523604001,
0.180178217975313,
0.20308584941119,
0.203884003544976,
0.240421881913085,
0.305001764731783,
0.196598460818313,
0.202902441606541,
0.167968154466311,
0.199955087856562,
0.172373647324672,
0.213421120095906,
0.196705428238404,
0.338577413899305,
0.19002379912503,
0.234112821836512,
0.26849253899321,
0.211876642968247,
0.243373744853905,
0.274827543674211,
0.20338211880963,
0.220050935322843,
0.211864658778423,
0.175179064564807,
0.265727387177693,
0.208547408214913,
0.326598732786511,
0.209563680243458,
0.22435068632286,
0.219650954906015,
0.212405599884125,
0.190624143132632,
0.240565744719565,
0.257548700955123,
0.216182620743396,
0.175446020027803,
0.227540129469127,
0.198860411804427,
0.203389912890561,
0.204625983303892,
0.214565368435734,
0.168616453895999,
0.190265916943314,
0.229741571933169,
0.317043440592801,
0.184172024726355,
0.2748475074961,
0.341578880584216,
0.272005292742882,
0.193836400874127,
0.226612968926386,
0.213773894092803,
0.208134628711545,
0.191089938186128,
0.222856719094344,
0.506387133649792,
0.199845750874926,
0.207910379556996,
0.195531231586025,
0.328423357098504,
0.304765474434008,
0.200699297461214,
0.196835461555169,
0.185438923940554,
0.421507030882521,
0.195952756297554,
0.242418423385753,
0.198723949961846,
1.52764833135362,
0.180139666958911,
0.1822847025192,
0.21567884104879,
0.224327485817,
0.170358717679317,
0.219406249712663,
0.194966274190596,
0.19391390025223,
0.194743296569751,
0.409721457588268,
0.349812088381184
),
stat = c(
-10.8695154836853,-10.4814902954635,
-10.1608707887438,
-8.92307113650685,
-8.65557677088328,-8.47301431341972,
-8.44259344971681,
-8.23665935274265,
-8.23183092478539,-7.68736237363899,
-7.6767233369232,
-7.65283012543889,
-7.59579113275195,-7.59338896607274,
-7.55500874784385,
-7.55109166822042,
-7.49182193520782,-7.36447129625382,
-7.35564291352484,
-7.34557121502962,
-7.29124745628436,-7.08091608800518,
-6.92488716839754,
-6.8007410068578,
-6.79737414128105,-6.71042362445978,
-6.68195206180926,
-6.61944717093717,
-6.59468332930334,-6.52615054535596,
-6.48123947078777,
-6.42906820735649,
-6.41909030336341,-6.39850159854015,
-6.36425118122701,
-6.32857331091192,
-6.2703178065874,-6.22824693961679,
-6.06313953787987,
-6.03944269701142,
-5.98477503996216,-5.93923899034433,
-5.8607977403763,
-5.85800080209783,
-5.84192903173701,-5.82696432390666,
-5.80766696760387,
-5.78488237970379,
-5.76450071852594,-5.76287864628693,
-5.75394353809847,
-5.73872933876173,
-5.68308445154149,-5.66691682293545,
-5.6586340301351,
-5.64380836216335,
-5.6302301028971,-5.62530405322348,
-5.62119112396476,
-5.61261134635839,
-5.59996800981492,-5.58467319738573,
-5.57877451488317,
-5.56670601599486,
-5.56134895678819,-5.54690042801847,
-5.52235731257289,
-5.48222978947769,
-5.47352305309644,-5.44167829843059,
-5.44027833141632,
-5.4380676116537,
-5.42138105495131,-5.42095959152896,
-5.40784642863302,
-5.40716801073286,
-5.40022943044848,-5.36980924861844,
-5.33161093403283,
-5.32276246299564,
-5.24832028313228,-5.2382981861532,
-5.18687502334554,
-5.15821492979127,
-5.15640070025306,-5.15362443765564,
-5.11687671125937,
-5.1130367658494,
-5.10805545240403,-5.10796220952272,
-5.09651280809281,
-5.0922378343971,
-5.04464876197518,-5.04443515387198,
-5.02750081046668,
-5.01487625829358,
-5.00509219744,-4.93312530480341,
-4.92608415652488,
-4.91620859972055
),
pvalue = c(
1.6105384639475e-27,
1.05074740468397e-25,
2.96417079172965e-24,
4.53533247814602e-19,
4.90425259485203e-18,
2.39123187387306e-17,
3.10373110219135e-17,
1.77085766196957e-16,
1.84373366907983e-16,
1.50199274107305e-14,
1.63209389674989e-14,
1.96603559055405e-14,
3.05917620449718e-14,
3.11645243316854e-14,
4.18831703432537e-14,
4.31624897911202e-14,
6.79240353188074e-14,
1.77850315040926e-13,
1.90010340573178e-13,
2.04882205246095e-13,
3.07098109300135e-13,
1.43204600625457e-12,
4.36323144701782e-12,
1.04082390918688e-11,
1.06543153285088e-11,
1.94060198761294e-11,
2.35780162668781e-11,
3.60544662066692e-11,
4.26164506980583e-11,
6.74814962119917e-11,
9.09721474995461e-11,
1.28388512236458e-10,
1.37091073947096e-10,
1.56909101165909e-10,
1.96244766091023e-10,
2.47438291649186e-10,
3.60311927938281e-10,
4.71683204808732e-10,
1.33489754819337e-09,
1.546474198518e-09,
2.16689139501711e-09,
2.86348175138605e-09,
4.60648782663971e-09,
4.68472389599416e-09,
5.15997893490219e-09,
5.64446727370089e-09,
6.33493652297021e-09,
7.25630841901856e-09,
8.18999292285693e-09,
8.26912538076218e-09,
8.71852861804007e-09,
9.53895256422316e-09,
1.3228690336629e-08,
1.45389874839546e-08,
1.52582531109057e-08,
1.6632920782743e-08,
1.79969358842075e-08,
1.85181504215372e-08,
1.89645323089349e-08,
1.99295886015674e-08,
2.14391365344425e-08,
2.34140076079223e-08,
2.4221898181661e-08,
2.59599819464236e-08,
2.676973112306e-08,
2.9077822326956e-08,
3.34481404929465e-08,
4.19998201908752e-08,
4.4117546051232e-08,
5.27809286620383e-08,
5.3197393894889e-08,
5.38615366672493e-08,
5.91403422530529e-08,
5.92799600367521e-08,
6.3787081174538e-08,
6.40290759293059e-08,
6.655572267256e-08,
7.88199674497518e-08,
9.73453251050117e-08,
1.02203166303607e-07,
1.53492275501923e-07,
1.62064065367655e-07,
2.13852137781182e-07,
2.49315333058881e-07,
2.51741885853566e-07,
2.55499393055106e-07,
3.10636522834479e-07,
3.17020565839737e-07,
3.25491137576376e-07,
3.25651758940819e-07,
3.45967166361943e-07,
3.53861823338068e-07,
4.54355220920421e-07,
4.54863057911226e-07,
4.96913387510328e-07,
5.30676077367893e-07,
5.5835300049354e-07,
8.09242026518054e-07,
8.38938764362226e-07,
8.82363768510161e-07
),
padj = c(
1.38425780976288e-23,
4.51558697162934e-22,
8.49234931830545e-21,
9.74529566241627e-16,
8.43041021055063e-15,
3.42543965932315e-14,
3.81093840333353e-14,
1.76076565397124e-13,
1.76076565397124e-13,
1.27525882205139e-11,
1.27525882205139e-11,
1.40817299173434e-11,
1.91327919022026e-11,
1.91327919022026e-11,
2.31863499846674e-11,
2.31863499846674e-11,
3.43415931508911e-11,
8.4923525432042e-11,
8.59546777487613e-11,
8.80481277045092e-11,
1.25690869020698e-10,
5.59474337443546e-10,
1.56258226196326e-09,
3.52207077878972e-09,
3.52207077878972e-09,
6.17758299390119e-09,
7.23760892192204e-09,
1.06857978291835e-08,
1.22096131249937e-08,
1.87097890303893e-08,
2.44345502424562e-08,
3.34393715961319e-08,
3.46558170757439e-08,
3.85323921291711e-08,
4.68534379042317e-08,
5.74792463979664e-08,
8.14968689639349e-08,
1.03951721675155e-07,
2.8683611066805e-07,
3.24193798445419e-07,
4.43438846194573e-07,
5.72363387282863e-07,
8.94782264134885e-07,
8.94782264134885e-07,
9.64130846640964e-07,
1.032216940797e-06,
1.13434957114435e-06,
1.27281573186662e-06,
1.39359083622845e-06,
1.39359083622845e-06,
1.44107218215489e-06,
1.5469301375377e-06,
2.10556654524678e-06,
2.27204722590164e-06,
2.34186938371847e-06,
2.50806937066098e-06,
2.66695972284074e-06,
2.69768648937478e-06,
2.71666925325493e-06,
2.80811170541757e-06,
2.97208675021828e-06,
3.19433960936654e-06,
3.25292523236525e-06,
3.43270838199247e-06,
3.48614907579849e-06,
3.73020720746548e-06,
4.22774658142464e-06,
5.23171673247206e-06,
5.41700440443342e-06,
6.34164257061655e-06,
6.34164257061655e-06,
6.34164257061655e-06,
6.79348342021179e-06,
6.79348342021179e-06,
7.14714165730369e-06,
7.14714165730369e-06,
7.33392867141863e-06,
8.5754129143116e-06,
1.04585383659697e-05,
1.08448915355494e-05,
1.60886110724272e-05,
1.6782417371506e-05,
2.18816562408246e-05,
2.51595524292023e-05,
2.51595524292023e-05,
2.52415779690648e-05,
3.03400103836631e-05,
3.06156377909274e-05,
3.07579875614982e-05,
3.07579875614982e-05,
3.23216064660967e-05,
3.27036814149537e-05,
4.11531366604946e-05,
4.11531366604946e-05,
4.44892767255341e-05,
4.70222771647117e-05,
4.89698371351222e-05,
7.02569213931583e-05,
7.21067867969333e-05,
7.50882830727212e-05
),
mark = c(
"",
"",
"",
"ENSG00000008988",
"ENSG00000156508",
"ENSG00000167658",
"",
"ENSG00000109475",
"",
"",
"",
"ENSG00000026025",
"",
"",
"ENSG00000070756",
"",
"",
"",
"",
"",
"",
"",
"ENSG00000186468",
"",
"",
"",
"ENSG00000149273",
"ENSG00000147403",
"ENSG00000137154",
"",
"ENSG00000198755",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"ENSG00000166441",
"",
"",
"ENSG00000187109",
"",
"",
"",
"ENSG00000110700",
"",
"",
"ENSG00000133112",
"",
"",
"ENSG00000145425",
"",
"ENSG00000122406",
"",
"",
"ENSG00000170889",
"ENSG00000105372",
"",
"",
"",
"ENSG00000198918",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"ENSG00000174748",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"ENSG00000114391",
"",
"",
"ENSG00000142937",
"",
"",
"",
"ENSG00000125691",
"",
""
),
gene = c(
"",
"",
"",
"RPS20",
"EEF1A1",
"EEF2",
"",
"RPL34",
"",
"",
"",
"VIM",
"",
"",
"PABPC1",
"",
"",
"",
"",
"",
"",
"",
"RPS23",
"",
"",
"",
"RPS3",
"RPL10",
"RPS6",
"",
"RPL10A",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"RPL27A",
"",
"",
"NAP1L1",
"",
"",
"",
"RPS13",
"",
"",
"TPT1",
"",
"",
"RPS3A",
"",
"RPL5",
"",
"",
"RPS9",
"RPS19",
"",
"",
"",
"RPL39",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"RPL15",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"RPL24",
"",
"",
"RPS8",
"",
"",
"",
"RPL23",
"",
""
),
genecolor = c(
NA,
NA,
NA,
"red",
"red",
"red",
NA,
"red",
NA,
NA,
NA,
"red",
NA,
NA,
"red",
NA,
NA,
NA,
NA,
NA,
NA,
NA,
"red",
NA,
NA,
NA,
"red",
"red",
"red",
NA,
"red",
NA,
NA,
NA,
NA,
NA,
NA,
NA,
NA,
NA,
"red",
NA,
NA,
"red",
NA,
NA,
NA,
"red",
NA,
NA,
"red",
NA,
NA,
"red",
NA,
"red",
NA,
NA,
"red",
"red",
NA,
NA,
NA,
"red",
NA,
NA,
NA,
NA,
NA,
NA,
NA,
NA,
NA,
NA,
NA,
NA,
NA,
"red",
NA,
NA,
NA,
NA,
NA,
NA,
NA,
NA,
NA,
NA,
NA,
NA,
"red",
NA,
NA,
"red",
NA,
NA,
NA,
"red",
NA,
NA
)
),
row.names = c(NA, 100L),
class = "data.frame"
)