Sergio Fonda
2015-Sep-06 22:36 UTC
[R] boxplots facets in ggplot, generated with two factors interaction mediane-ordered
Sorry for repeating the message owing to previous uncorrect html version delivered (Thank you bert Gunter for the alert). Marc Schwartz enabled me to order a "two factors" interaction boxplot with median associated to one factor alone: thanks. I tried further to generate facets plot (3x2 boxplots in ggplot2) for the dataframe reported at bottom and I'm not able to reach a correct plot. The dataframe is a simulation of genes expressions in five conditions of patients. I would like that each of the 5 boxplots were ordered with median of values associated to the combination "gene*pat.cond". Any help is much appreciated, Sergio ____________________________ Example Dataframe: DF <- structure(list(pat.cond = structure(c(3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 4L, 3L, 1L, 2L, 2L, 2L, 5L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 2L, 2L, 2L, 5L, 5L, 5L, 3L, 1L, 1L, 1L, 2L, 5L, 5L, 5L, 5L, 3L, 3L, 1L, 2L, 3L, 3L, 2L, 4L, 4L, 4L, 5L, 5L, 3L, 2L, 3L, 3L, 1L, 1L, 2L, 5L, 1L, 1L, 2L, 2L, 4L, 5L, 2L, 2L, 2L, 5L, 5L, 5L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 5L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 5L, 3L, 1L, 2L, 5L, 3L, 3L, 1L, 1L, 1L, 1L, 5L, 2L, 2L, 2L, 2L, 4L, 4L, 5L, 5L, 5L, 3L, 3L, 3L, 1L, 1L, 2L, 5L, 3L, 2L, 2L, 2L, 5L, 3L, 1L, 2L, 5L, 1L, 2L, 5L, 5L, 3L, 1L, 5L, 3L, 1L, 1L, 1L, 2L, 5L, 5L, 3L, 1L, 5L, 5L, 1L, 1L, 2L, 5L, 5L, 3L, 1L, 1L, 2L, 4L, 5L, 2L, 4L, 5L, 5L, 5L, 3L, 1L, 2L, 5L, 5L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 4L, 5L, 5L, 5L, 3L, 3L, 1L, 1L, 3L, 3L, 1L, 1L, 5L, 5L, 5L, 5L, 3L, 2L, 2L, 4L, 5L, 3L, 1L, 1L, 1L, 2L, 2L, 5L, 5L, 3L, 1L, 1L, 2L, 2L, 4L, 5L, 5L, 5L, 2L, 2L, 4L, 4L, 5L, 5L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 1L, 1L, 5L, 5L, 1L, 2L, 5L, 4L, 5L, 5L), .Label = c("E", "M", "N", "R", "S"), class = "factor"), gene = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 27L, 27L, 27L, 27L, 27L, 27L, 28L, 28L, 28L, 28L, 28L, 29L, 29L, 29L, 29L, 29L, 30L, 30L, 30L, 30L, 30L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 32L, 32L, 32L, 32L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 34L, 34L, 34L, 34L, 34L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 37L, 37L, 37L, 37L, 37L, 37L, 38L, 38L, 38L, 38L, 38L, 38L, 39L, 39L, 39L, 39L, 39L, 40L, 40L, 40L, 41L, 41L, 41L), .Label = c("ADAMTS1", "ADAMTS12", "APC", "BORIS", "BRCA1", "P16", "DAX1", "DKK1", "DKK2", "ESR1", "FBP1", "FOXL2", "GATA5", "GPX3", "MAL", "MGMT", "MLH1", "MYOD1", "NELL1", "OSMR", "PAX6", "PTGS2", "RARB", "RASSF1A", "RPRM", "RSPOI", "SEPTIN9", "SFRP1", "SFRP4", "SFRP5", "SMAD4", "SOCS3", "SPARC", "TAC1", "TERT", "TIMP3", "TMEFF2", "WIF1", "WNT4", "WRN", "WT1"), class = "factor"), value = c(-5.55719429171322, -2.57670015708011, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -2.74216370891365, -1.08410461110653, 1.71087195329919, 6.62935662007961, 6.62935662007961, 1.71142268170053, -3.66516900838688, -1.1921835776928, -6.62935662007961, 3.69654219362645, -3.53399164077955, -4.26788713377028, 6.62935662007961, 6.62935662007961, 6.62935662007961, 6.62935662007961, 6.62935662007961, 6.62935662007961, -4.26034786170766, -6.62935662007961, -6.62935662007961, -6.44317496711901, -6.62935662007961, -6.62935662007961, -2.52597228116937, -1.69870667463154, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, 0.518269571084176, 0.708010227963537, -0.337455349570156, 2.80337460503403, -1.40722622802079, 6.62935662007961, 2.0224084987157, 6.62935662007961, 6.62935662007961, 6.62935662007961, -0.876905559086274, 0.00817656528033632, -3.0570810238408, 0.804046915404625, -4.67788067608942, -3.26418214278398, 0.219772060806496, -3.20576041923257, -3.56779953667954, -1.68711309148568, -6.62935662007961, -6.62935662007961, 1.47981002017674, 1.86101101355619, -0.110196473063222, 0.721286184467319, -5.10794386813511, -4.59381236574539, -1.6221766881308, -3.09779152534191, -4.56412323856937, 3.11118043673057, 0.323703764100918, -3.85135048527067, -3.32408752349639, 0.73940898934279, -1.17193224621231, -3.46605473088182, -1.28303869901795, -2.77839069037272, -2.01447927302819, -3.01523417249907, -6.62935662007961, -1.94219073489774, 6.62935662007961, -6.62935662007961, -2.61598244990042, -6.62935662007961, 0.128743354288953, -6.62935662007961, -6.62935662007961, -4.82554545191733, -6.62935662007961, -6.62935662007961, -6.62935662007961, -0.41900536366504, -0.923667454545306, 6.62935662007961, 3.37174019620549, -6.62935662007961, -6.62935662007961, 1.11511255641923, 4.03089379683332, -6.62935662007961, -0.51987530372271, -1.35287208430557, -0.777864442364311, 1.10507302913784, 5.75869919923622, -1.49807223582966, -1.63036230103387, -6.62935662007961, 6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -4.64505378091392, -6.62935662007961, -5.53659155714965, -5.90385655188777, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, 4.40782183888056, 0.364604850758639, -6.62935662007961, -6.62935662007961, 6.62935662007961, -3.40103095864142, -0.946878855241565, 0.964721064911626, -3.74979523988984, -6.62935662007961, -2.07635665640007, -3.96116491608577, -4.61142917326893, -1.70616643169626, -3.69749323087937, -1.5051286418556, 0.808179628116493, -6.62935662007961, -0.694997777544086, -0.33230757657502, -6.62935662007961, 6.62935662007961, -4.0235234663823, 0.443243994976371, -6.62935662007961, -4.01927003836633, -1.73530760747145, -1.29608320459239, -3.00375275640445, -3.15656493554918, -2.92887173087699, -6.62935662007961, -2.58546973110719, -2.52579826365207, 6.62935662007961, -3.07122225341412, -6.62935662007961, -1.42646581480733, -6.62935662007961, -2.34864875081226, -6.62935662007961, -2.30429527278787, -2.3150449014819, -2.94015813861698, 6.62935662007961, -6.62935662007961, 6.62935662007961, -6.62935662007961, -5.83352339310267, 2.76566615565279, 2.7077349216041, 6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -0.604614698290898, 0.0972686463523985, -1.50545021800149, 6.62935662007961, -3.86563998837838, -1.86878292774122, 2.82104606819918, 6.62935662007961, -6.62935662007961, 0.20201788697105, 6.62935662007961, 6.62935662007961, -1.52822157760479, 6.62935662007961, 6.62935662007961, -2.29426725030903, 2.6245946340759, -2.98564123198612, 2.80974772888437, 6.62935662007961, -3.16440463278017, 6.62935662007961, -2.76688110755984, 0.875337371866448, 3.17509546138607, -2.04672929806323, -3.46140822952959, -2.99672055669611, -6.62935662007961, -1.52733314896727, -3.93365728287806, -1.0201449757102, -2.35711287350022, 0.806736362269386, -1.16027585023965, -2.71202580562016, -3.96147823714849, -6.51095371428348, -0.619555285633288, 2.344341056524, -6.62935662007961, -3.80611452228589, -2.31831315765999, 1.10289989684782, 6.62935662007961, -6.62935662007961, -6.62935662007961, -3.47402718515842, -6.62935662007961, -6.62935662007961, -6.62935662007961, -6.62935662007961, -4.14894298549979, -1.85599414152503, -0.824982393234853, 1.23612950069026, 1.08854087705027)), .Names = c("pat.cond", "gene", "value"), row.names = c(NA, -244L), class = "data.frame")