Home > Blockchain >  Horizontal bars with stars realative to each pairwise comparison into boxplots
Horizontal bars with stars realative to each pairwise comparison into boxplots

Time:11-13

I'm trying reporting into the following plot some multiple pairwise comparison. In order to this I have just scripted down the following code

p <- ggboxplot(data, x = "COND", y = "P3(400-450).Pz",
               color = "SES", palette = "npg",
               facet.by = "SES", short.panel.labs = FALSE)
# Use only p.format as label. Remove method name.
p   stat_compare_means(
  aes(label = paste0("p = ", ..p.format..))
) 
  stat_compare_means(method = "t.test", label.y = 40)  # Add global p-value
  stat_compare_means(aes(label = ..p.signif..),
                     method = "t.test", ref.group = "NEG-CTR")

Just by using the showing horizontal bars for pairwise comparisons and stars for significant difference, like in the following example.

enter image description here

I am not sure whether I picture exactly the idea, but does anyone know what am I suppose to do?

> dput(head(data, 50))
structure(list(ID = c("01", "01", "01", "01", "01", "01", "01", 
"01", "01", "02", "02", "02", "02", "02", "02", "04", "04", "04", 
"04", "04", "04", "04", "04", "04", "06", "06", "06", "06", "06", 
"06", "06", "06", "06", "07", "07", "07", "07", "07", "07", "07", 
"07", "07", "08", "08", "08", "08", "08", "08", "08", "08"), 
    GR = c("RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", 
    "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", 
    "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", 
    "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", 
    "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", 
    "RP"), SES = c("L", "L", "L", "R", "R", "R", "V", "V", "V", 
    "L", "L", "L", "R", "R", "R", "L", "L", "L", "R", "R", "R", 
    "V", "V", "V", "L", "L", "L", "R", "R", "R", "V", "V", "V", 
    "L", "L", "L", "R", "R", "R", "V", "V", "V", "L", "L", "L", 
    "R", "R", "R", "V", "V"), COND = c("NEG-CTR", "NEG-NOC", 
    "NEU-NOC", "NEG-CTR", "NEG-NOC", "NEU-NOC", "NEG-CTR", "NEG-NOC", 
    "NEU-NOC", "NEG-CTR", "NEG-NOC", "NEU-NOC", "NEG-CTR", "NEG-NOC", 
    "NEU-NOC", "NEG-CTR", "NEG-NOC", "NEU-NOC", "NEG-CTR", "NEG-NOC", 
    "NEU-NOC", "NEG-CTR", "NEG-NOC", "NEU-NOC", "NEG-CTR", "NEG-NOC", 
    "NEU-NOC", "NEG-CTR", "NEG-NOC", "NEU-NOC", "NEG-CTR", "NEG-NOC", 
    "NEU-NOC", "NEG-CTR", "NEG-NOC", "NEU-NOC", "NEG-CTR", "NEG-NOC", 
    "NEU-NOC", "NEG-CTR", "NEG-NOC", "NEU-NOC", "NEG-CTR", "NEG-NOC", 
    "NEU-NOC", "NEG-CTR", "NEG-NOC", "NEU-NOC", "NEG-CTR", "NEG-NOC"
    ), `P3(400-450).FCz` = c(-13.733750856001, -11.0706676917232, 
    -8.4719202003519, -5.04318152659785, -6.25375875400145, -7.0474968134059, 
    -11.6312151716924, -11.1438413285935, -3.99591470944713, 
    8.71618523084192, 3.1567164130045, 0.11779005903818, 6.2230923800622, 
    0.545039723311392, -0.383605036065646, -2.10936383457265, 
    1.81064934015995, 0.754416368133019, -1.2371236814317, -2.76852389876276, 
    5.54144355778122, -0.314155675382471, 0.238885648959708, 
    5.03749946898385, 0.515492206557273, -3.44241289723487, -3.60371878191807, 
    2.15744073519755, 2.97044048166016, 0.826471695322022, -0.213621915029167, 
    -2.96032491743069, -1.97168681693488, 6.07627585156856, 2.65607069005775, 
    2.167137857557, -6.27800355104694, 1.09308182001875, -1.66840335868091, 
    -2.83109425298642, 1.09291198163802, -6.692991645215, 2.52780299526812, 
    5.27990401221703, 5.99976721968901, 9.24978801123206, 0.425329980369809, 
    1.71912357557142, 4.23849942428043, 2.9898889629932), `P3(400-450).Cz` = c(-9.75024624896264, 
    -8.42427447113084, -5.61886494275071, 0.73152672768007, 1.11453058993788, 
    -2.25104720773472, -5.16524399006139, -5.53112490175437, 
    0.621502123415388, 10.0972150696175, 3.29671672118792, 0.527314779744752, 
    7.48013969467974, 2.24297008138028, -0.0523505792147314, 
    0.0473343786951428, 2.78240093455642, 2.60057993978525, 1.4302038359579, 
    -0.650797837853182, 7.81248993867768, 2.23100741241039, 3.96990710862955, 
    7.75899775608441, 0.204266730001714, -3.87922889171612, -4.52390680893631, 
    -0.555866517774192, 4.83800866902117, 0.386260399882896, 
    -1.30019374375434, -3.59899040898949, -1.92340529575071, 
    7.24382761640437, 5.07346604438783, 1.24302811983358, -4.32716726630564, 
    -0.38950039454238, -1.00946943140895, 2.19344184533265, 5.87900720863083, 
    -5.92378937757888, 3.7522867230774, 4.82216351833378, 6.82409510730108, 
    7.49006852363704, -0.300057129806311, -1.50815653499612, 
    2.44958531767688, 3.10043497883256), `P3(400-450).Pz` = c(2.65626156135631, 
    3.37360619561252, 5.4043480635031, 19.5226358864568, 18.5017390789352, 
    11.7844254386573, 11.8802266972569, 12.1053426662461, 12.955441582096, 
    13.9718285231429, 6.37710361710325, 3.52040283490143, 13.9681839573434, 
    8.64955428897889, 2.80847380898547, 10.1644392609445, 13.2788201390174, 
    10.5077997492971, 13.4030666728381, 4.74014346829081, 11.9003140352528, 
    15.0981004360619, 15.4046229884164, 16.671036999147, 6.24616732032065, 
    4.78883251402879, 3.10163832479954, 7.19701911286765, 11.7708849923357, 
    4.76130184268843, 3.13771453335467, -0.0892565159000666, 
    2.15365554736525, 14.2288406703293, 15.1061639215556, 14.7526139656351, 
    4.40802638411125, 5.99762046600297, 7.92311316925979, 13.6778924406572, 
    14.3862738306396, 6.86762877785576, 11.3514279090328, 10.757070094133, 
    12.5234783491609, 11.9523047880127, 5.0297404208255, 2.02597583125742, 
    7.47946451329025, 8.93405130318593), `LPPearly(500-700).FCz` = c(-11.2145748677083, 
    -13.9481657323772, -12.0047623683783, -4.24372139176794, 
    -7.38414465678688, -6.61221718491095, -11.7785042972793, 
    -9.14927207125904, -7.58190508537766, 14.2438131545118, 10.3728637305957, 
    4.71555467505934, 8.16263381384371, 2.54754270788021, -1.01463338713448, 
    -6.4216236476269, -4.08374576377548, -8.46742290376216, -6.30908300837476, 
    -6.72661142802369, -3.32736490042247, -4.01515836011381, 
    -6.60165385653499, -2.02861964460179, 5.8666814083179, 2.33082585113171, 
    2.40451234371064, 1.05508424329473, 5.3097315293492, 1.70929976001852, 
    4.46729570509601, 2.54036572774646, 2.22923889930115, 7.6624459254463, 
    6.18258235027347, -0.203182430749258, -2.27129671832951, 
    5.40263488258673, -4.20502646350577, -0.883620011106743, 
    -2.63569087592267, -2.0629672230873, 4.47898231370857, 1.80519919233502, 
    3.0454688268426, 6.18699806432327, 1.25405112888438, -0.11418325531592, 
    1.14544537612393, 2.08056674659401), `LPPearly(500-700).Cz` = c(-8.14861856277773, 
    -11.7645758007163, -9.16726244915301, 0.918751423320568, 
    -0.674372568935879, -2.47425935490564, -5.96429031525769, 
    -5.10918437158799, -2.81732229625975, 18.1277616996079, 14.0324104861749, 
    7.88901307601169, 10.9263261999576, 5.40070389371842, 0.139150314055044, 
    -4.61042211238648, -3.5562551128714, -6.85651693740331, -2.17237957159954, 
    -6.18867237684241, -1.77938930999718, -1.43557366487622, 
    -3.14872157912645, 0.160393685024631, 6.04784652351361, 3.3201189812225, 
    2.77790257477581, -0.0321863430056016, 8.03888173016662, 
    2.16769713008185, 3.52155765271648, 2.10437989449921, 2.70693992810407, 
    10.2402460112877, 10.5847649678568, 2.99156139408255, 0.987380045459147, 
    6.18423974949375, -0.40265090814513, 5.49897156207812, 5.81171180245335, 
    -1.37301251388987, 5.2730385884406, 1.39951691713478, 4.53957911434179, 
    4.37989532381317, 0.03009474232655, -1.79066490738329, -0.434363848460157, 
    2.87987510596148), `LPPearly(500-700).Pz` = c(3.4315211013568, 
    -1.55179922542943, 1.13509020104859, 16.3120391015512, 14.1694182774958, 
    9.04781409226351, 8.23981597718437, 9.51261484648731, 9.42367409925817, 
    20.6284861844249, 17.1194345279475, 9.74981375898379, 15.5578942384162, 
    10.3425870381822, 3.41932708826405, 4.05274207265641, 3.767844291789, 
    0.326110657534835, 6.65839865279684, 1.17003883692158, 5.40630013085777, 
    5.06332653216481, 5.02619159395405, 9.07903916629231, 11.3067210486656, 
    9.74936883279237, 9.14893956441953, 7.00923591763326, 15.2010764804929, 
    8.29325466843138, 7.56089165217984, 5.49719893790597, 4.91476855238182, 
    17.0746332933437, 16.4557870433523, 12.5386217802264, 9.96296384449786, 
    12.6285790535059, 7.51544082181442, 13.0320953572069, 10.8414516494484, 
    5.86927622259489, 8.4679745206329, 5.2174731744097, 8.61228643159009, 
    8.25866995489044, 4.87548371372039, 0.574498421605017, 3.25309970442897, 
    4.6847880297099), `LPP1(500-1000).FCz` = c(-7.774797181711, 
    -8.40872060176111, -7.03235376576925, -0.65010821749741, 
    -3.24350263682843, -2.84832379590422, -5.67295796971287, 
    -4.3918290080777, -2.96652960658775, 12.5228696634748, 10.1688421767607, 
    4.94891653050796, 8.29234474523583, 2.89989209310052, 1.69916872833203, 
    -1.13332962482291, 0.649857280429136, -4.43684347222634, 
    -2.31574543509226, -2.73359549382074, -0.38736451456005, 
    0.159183652691071, -1.78361184935376, 1.97377908783621, 6.83112977894818, 
    1.66856860799729, 1.50685192543202, 2.41771490245341, 4.37926203865435, 
    0.172003204109993, 3.17401220482225, 1.60211665164145, 2.27932356239417, 
    8.03331913665274, 7.41512588618407, 1.79879051600465, -1.26594212720465, 
    5.95059437885331, -1.32233316983404, 2.41479226362682, -0.16792378673807, 
    1.37236796086306, 3.10731797680438, 0.794474122791628, 0.851147671069733, 
    5.64784381556438, 1.54994566287677, -0.0981813709092295, 
    1.17012593697048, 1.40362599894122), `LPP1(500-1000).Cz` = c(-5.0379636708446, 
    -6.36865552801825, -4.54670193355435, 4.05493850786385, 2.67516303169366, 
    1.02479302810681, -0.774461731301161, -0.650009462761383, 
    1.14010250644923, 15.0856583318757, 12.7218688256241, 7.04929483656524, 
    9.71944484568732, 5.19815917760722, 2.20513206952329, -0.20305866581144, 
    1.01053594416015, -2.96241685765962, 1.26480036715092, -2.00512841997728, 
    -0.423105565152366, 1.51403741206392, 0.25571835554024, 3.76051565494304, 
    6.84424120299137, 3.42983447849866, 1.92879865454881, 1.33136574265339, 
    7.29405407117465, 0.983842959739636, 2.74763442988403, 1.09116707485702, 
    3.29833843753872, 10.5933306260989, 10.4464306355299, 3.30170136471424, 
    1.45130891069149, 6.63174942084737, 1.71811902258049, 6.55857216695288, 
    7.06029312947389, 0.6053954850232, 3.8513036082268, 0.00774607979315, 
    2.19540210527734, 3.85784290492868, 0.23258794277576, -2.03599888335028, 
    -0.362612239707932, 2.72729847885135), `LPP1(500-1000).Pz` = c(4.67200616533014, 
    1.75888442936359, 2.49276476951357, 13.8997702651793, 13.2135623121441, 
    9.51479768101391, 9.99385579756163, 11.1212652173052, 10.6989716871958, 
    15.4011622649207, 13.5845965959489, 7.62145250862908, 12.4214977980377, 
    8.94731174966949, 4.10953557761617, 5.80373742668179, 5.74639215930458, 
    1.48762660613099, 6.04018553841336, 1.9050381096835, 6.37211228749408, 
    3.7899021820967, 4.59413830322224, 8.52123662617732, 11.0326576935158, 
    8.53328996612415, 7.97978028439358, 8.06029747262827, 13.6951238953551, 
    5.8513720384409, 6.34418311104072, 4.10771312429751, 4.94124365003338, 
    15.4260452192155, 14.2517590882885, 9.27715192618166, 9.03771312379889, 
    10.7215413815321, 5.94571628715645, 11.8912196156261, 10.1332638103233, 
    5.33467168055784, 4.57329045675327, 1.80936561040356, 3.43314757844849, 
    4.6626272499834, 3.76342973499868, -2.21571300772636, 1.04545904874305, 
    2.86650202467156), `LPP2(1000-1500).FCz` = c(-0.397250087672501, 
    1.01519755373062, -1.17300033366376, 0.663115370014327, -1.72160165493474, 
    0.0540027107377267, -0.198736254963744, -3.16101041766438, 
    0.895992279831378, 9.21248347391488, 4.2029104966206, 5.29260474692784, 
    4.43538787409554, 1.28346027317076, 1.17003451023205, 3.21881665778703, 
    5.92604591551597, -2.75555354427229, 2.18006640865321, -0.225533814334514, 
    0.986467266459687, 3.11042068112836, 2.27800090558473, 3.83846437952292, 
    2.11741401205978, 2.41324857857743, 2.60828710695631, 1.84146702695206, 
    2.1796529384155, 0.357695315581409, 0.70169995101623, 1.75290674648806, 
    -1.33916628569866, 5.54833202313032, 6.28414577615156, 0.270980091955565, 
    -0.243931314877871, 4.36296654230765, 2.34260355786884, 6.69246804853767, 
    4.76363910849669, 5.6387334295083, 2.51614439050594, 0.544519979811557, 
    -1.14127513231745, 7.01169149718639, -0.0444060583672976, 
    -0.266568732466728, 1.37744267413711, 0.973396686787801), 
    `LPP2(1000-1500).Cz` = c(2.91913936481813, 1.85489998202138, 
    0.694393606954545, 3.95694572160701, 2.36649557381131, 2.71292196345657, 
    2.96437294922766, -2.12913230708907, 2.94619035115619, 10.0673617448764, 
    5.28032844958354, 5.76317883868431, 4.54790063971537, 2.16569592764593, 
    1.33824716938448, 2.58426832963409, 5.077230852852, -1.59699177169018, 
    6.61872855398538, -1.21696526578647, -0.507207892673482, 
    3.44844607014521, 3.02403433835637, 4.7045767546583, 1.31359485387859, 
    3.04464581710327, 2.0247782323911, -1.66589658134171, 2.27922842547595, 
    2.2302354828667, -0.119440173019054, 0.668265457194833, -0.405630185540259, 
    7.62396496656744, 8.44945750972713, 0.370915598749633, -0.147829603799427, 
    4.04101914581768, 3.17556880837002, 7.32640154038155, 6.75063445570149, 
    1.59973104216962, 3.24583129375449, -0.71967320732169, -0.0509722101281298, 
    6.0531518403553, -0.610046927519558, -2.83970701910469, 0.716894061961362, 
    1.15587576192688), `LPP2(1000-1500).Pz` = c(8.38141924882334, 
    4.88842858528025, 5.0594399581601, 3.88831364571248, 5.83201076558185, 
    3.65113189260335, 6.28027312932027, 5.24535230966772, 7.68162285335806, 
    8.55827491190151, 4.37390045274906, 4.27567967018154, 6.04702803069286, 
    5.29458007289059, 1.21234812875355, 6.30887598671621, 5.9614279900414, 
    -0.609381826740468, 3.66646157996528, 0.240956222277802, 
    1.15053325116554, 1.08242973465635, 2.99896314000211, 5.36085942954182, 
    2.79229514887897, 5.44503756798021, 5.10559083807721, 4.18316343024083, 
    7.57635217480856, 4.02825376191901, 1.22060069796986, 0.43007709818575, 
    0.476667611076957, 10.1988511186129, 6.91943531570565, 5.14515507518463, 
    4.85299225301444, 4.65269577391896, 2.79449493975094, 8.73650967214853, 
    7.20593389743811, 4.57722295263921, 0.0275313390411946, -2.25099759243389, 
    -1.97681061280815, 4.84396306101255, 0.490818836727051, -4.3981990809636, 
    -1.33620384654018, -1.28885901608471), `LPP2(1000-1500).POz` = c(9.61455213192824, 
    7.21299011910717, 6.1861244061312, 6.46723813995257, 7.25962635499353, 
    7.92952342178602, 7.91468942320841, 9.94838815736199, 10.2186482048953, 
    5.76901446016799, 1.63411653734436, 2.14044069620066, 4.09091078261671, 
    5.32593378182311, -0.0587064331536407, 6.86490468078958, 
    5.26280996552585, 0.981300734684586, 5.0384350436334, 0.361670119961531, 
    0.393791410918138, 1.07455889922813, 1.65917850515029, 3.22422743232682, 
    4.15964501337974, 5.35297505953096, 7.08169531735032, 4.11643541344308, 
    6.89982254066399, 5.50985275336188, 0.742475871599007, 3.46485267529148, 
    0.947548090127007, 7.78087935610006, 5.56652323496618, 5.90898158385732, 
    4.7450495762156, 6.10110636998382, 4.54176811122071, 4.48645178533554, 
    6.25868881853194, 3.58715194078339, -0.823830529987789, -2.33362938716716, 
    -2.76646353238667, 2.65023738859414, -1.22376317353831, -5.95366891057044, 
    -2.42743430604504, -1.97143573568321)), row.names = c(NA, 
-50L), class = c("tbl_df", "tbl", "data.frame"))
> 

CodePudding user response:

By trying with one of map() function of package purrr

##titles plots(.y) creation
names <- data_long %>% select(signals) %>% 
  unique() %>% pull(signals) %>% 
  sort() 

##data(.x) splitting
data_long_split <- data_long %>%
  split(data_long$signals)


plot_list <- imap(
  data_long_split,
  ~ ggboxplot(data = .x,
              x = "COND", y = 'value', 
              color = "COND", palette = "npg",
              facet.by = "SES", short.panel.labs = FALSE)   
    theme(axis.text.x = element_text(angle=90))   ylab(.y)  
    stat_compare_means(comparisons = my_comparisons, 
                       method = 't.test', 
                       label = "p.signif", ref.group = 'NEG-CTR') 
    ggtitle(paste0('Boxplot for multiple comparison', .y))
)
  • Related