Sort ggplot boxplots by median with facets - r

I'm trying to get ggplot to order my boxplots based on median value after splittin the data into several different facets.
This is part of a larger Shiny app I've written. Under default parameters, I can generate three faceted boxplots that order correctly:
boxData <- structure(list(Classification = structure(c(4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Pluripotent/ Undifferentiated",
"Endoderm", "Mesoderm", "Ectoderm"), class = c("ordered", "factor"
)), value = c(0.000255214868214152, 0.000108050996652777, 0.00751505823956855,
8.71801689770664, 5.71059263813113e-05, 4.90291746067526e-05,
0.000129388767504551, 2.52712436532327e-07, 5345.09546573398,
0.0020991194782334, 4.33360773005175e-06, 1.8200776481618, 3.44754305553851e-06,
4.38932775031697, 0.00720892572385782, 7.53517216121544e-05,
0.221288441144887, 0.00104230990042965, 0.00288742662358172,
4.20947546944294e-05, 9.62973878475845e-07, 0.00710967831313203,
26.9833955280036, 0.00265697432110539, 1.41814003567946, 0.261340025051291,
0.00159083508412152, 9.55044905589291e-06, 0.0122931632086495,
8.54789134364452e-06, 2.01899938950824e-05, 1.55354988683742e-06,
0.000441285511108929, 0.000353500530366103, 0.125347054487635,
109.440278770173, 2.03304264082645e-05, 2.01899938950824e-05,
0.000148628664387571, 2.89902659683517e-06, 207.073625180606,
3.52469070261441e-07, 3.15047327017105e-06, 0.639049681601525,
2.11937734339159e-05, 0.484309094613314, 0.0126387710681522,
0.000124981311087457, 0.010701820155981, 0.00520458916051572,
0.002548740132205, 6.70653961877279e-06, 1.1372650836283e-06,
0.0028674817110041, 6.38196191847228, 0.00104230990042965, 2.77791027153022,
0.385285554179204, 3.23552539344696, 0.00129215960928528, 3313.17800288969,
0.42454812322342, 0.427501088945987, 0.0252775421363044, 1.3790172222154e-05,
0.000499925244349826, 0.575943821174679, 3.66456124110476e-05,
0.000979273863184647, 1.71186456807568e-06, 0.000506903940694852,
3.95489796579998e-05, 7.60789146241221e-07, 5.53083255055159e-07,
0.000283178626588241, 5.68632541814152e-07, 89.5114292952616,
2.15183665744117e-06, 9.48447928546097e-06, 1.10616651011032e-06,
6.83831307491562e-05, 0.000231612381626088, 0.361984543094889,
5.91197625260395e-05, 0.000979273863184647, 2.83936549218472e-06,
0.000979273863184647, 5.11112358098405e-05, 1.714153924998e-07,
5.19634300333657e-07, 0.000285939985649123, 0.000340041865397713,
0.11809338012465, 60.884369685235, 2.29364239206782e-05, 1.59952159960469e-05,
0.000213718586351138, 2.65657707341963e-06, 3635.65603745587,
1.08786283557826e-07, 3.36257994807117e-06, 0.482299092292068,
1.40214978558205e-05, 0.506277403675245, 0.00847835446782661,
5.84677257215999e-05, 0.00674484030136259, 0.00483589957358377,
0.0017456741452281, 6.45120458509457e-06, 6.32689066217975e-07,
0.00245170310797391, 9.30496033238278, 0.000922604532223834,
1.94261499108326, 0.348202870167258, 0.000995700862302919, 9.18683915124066e-06,
0.00490340621594781, 9.51081233425213e-06, 1.64449027258861e-05,
1.32828853670982e-06, 0.000283964853893518, 0.000480891817820092,
0.103521332666818, 96.202334596196, 1.57750051307367e-05, 2.09600255345096e-05,
0.000200793473806753, 1.29196641682183e-06, 179.519904082227,
2.39744324779145e-07, 2.44454941589392e-06, 0.492433221447773,
1.07746460295468e-05, 0.437695664847132, 0.00947275639891981,
9.69768554804815e-05, 0.0056325346541415, 0.00470366164543522,
0.00172164093341244, 6.91422987569681e-06, 8.82439067876674e-07,
0.00253816223135828, 5.84822979360013, 0.000929021754230271,
2.31017156910716, 0.278934830581241, 2.84415482117455, 0.00100262650949219,
2661.45599990874, 0.357992185300285, 0.37579036951639, 0.0210213626331535,
1.87597483406766e-05, 4.9165300967331e-05, 0.353063601096188,
2.84344613435294e-05, 0.00277749494255326, 1.32828853670982e-06,
0.00108958918195797, 9.25073867082013e-06, 1.4059026149049e-07,
4.29154362580066e-07, 0.000537294242854559, 8.10925044524043e-06,
0.020165038913309, 9.91469621624329e-06, 1.63313094852695e-05,
8.58308725160133e-07, 2.34183669433728e-05, 0.000352033415883844,
0.28087497575791, 4.58728478413563e-05, 0.0007598488052299, 1.48407969771465e-06,
0.0223745115812679, 1.15479796826903e-05, 1.33006491938229e-07,
4.03200286568411e-07, 83.9815202938853, 211.131788444181, 1.73147313103931,
0.162893393670412, 6347.61978641754, 1.56049096034741, 0.532923368033971,
0.651573574681646, 22.0392007421302, 0.05154584678813, 85997.0767809387,
2.10234581817541, 1994.76074197656, 17462.8329237372, 1.76785506212734,
49735.9012814537, 1.57134503333516, 340.615434516655, 3.73730938753272,
2.07340220203944, 0.974004268543241, 53.8920290309386, 28.8800232787977,
0.0604547706008708, 6.41744933081988, 1.9615580079771, 0.384751805040216,
1.53900722016086, 1.68412590721683, 2.31658561238929, 1.62675839626425,
2.23767420207142, 1.67249279982813, 1.53900722016086, 1.51781925297405,
0.717972255311719, 1.08072540203935, 1.6958399292663, 1.74351647907412,
1.6958399292663, 0.98077900398855, 0.000159075579756261, 1.32133840565826,
1.57134503333516, 1.79253339913881, 2.00277451142267, 1.74351647907412,
2.66105808216138, 0.90250072746243, 2.059080166868, 1.50733490955838,
1.3966785324674, 1.61552155521922, 1.42602571736414, 1.90791910109511,
1.38703096913138, 1.38703096913138, 1.49692298679269, 1.69583992926629,
2.16145080407871, 2.67956720485568, 1.3966785324674, 1.53900722016086,
1.70763542878249, 0.921464186198703, 3.32188009636358, 10.5707072452661,
6.5522935828786, 1.68412590721683, 7.57896056479413, 1.43594451062343,
0.312515575646302, 34.1070955541741, 2339.52511354582, 11.0962477530511,
8.17942824487938, 1.68412590721683, 0.418123199957032, 804.528657067602,
0.679243142274472, 1.47631440568283, 1.75564359521904, 2.81278639982623,
4.14680440407889, 1.68412590721683, 2.33269873957693, 1.68412590721683,
1.70763542878249, 1.37745004638314, 1.68412590721683), listElement = structure(c(3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 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), class = "data.frame")
To generate the boxplot:
boxData$temp <- paste(substr(boxData$Classification,1,6),
as.character(boxData$listElement))
ggplot(boxData, aes(reorder(boxData$temp, value, median),value, fill=Classification))+
geom_boxplot()+
scale_y_log10()+
ylab("Fold Expression Change")+
xlab("Gene Classification")+
theme(axis.text.x=element_text(angle=90, hjust=1, size=6))+
facet_wrap(~listElement, scales='free', ncol=1)+
scale_x_discrete(labels=setNames(as.character(boxData$Classification), boxData$temp))
But if a parameter is changed and we only have two samples rather than three (In this case, the same data, but with twice as many 'endoderm' samples and no 'mesoderm' samples), the boxplots look really weird:
boxData <- structure(list(Classification = structure(c(4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Pluripotent/ Undifferentiated",
"Endoderm", "Mesoderm", "Ectoderm"), class = c("ordered", "factor"
)), value = c(0.000255214868214152, 0.000108050996652777, 0.00751505823956855,
8.71801689770664, 5.71059263813113e-05, 4.90291746067526e-05,
0.000129388767504551, 2.52712436532327e-07, 5345.09546573398,
0.0020991194782334, 4.33360773005175e-06, 1.8200776481618, 3.44754305553851e-06,
4.38932775031697, 0.00720892572385782, 7.53517216121544e-05,
0.221288441144887, 0.00104230990042965, 0.00288742662358172,
4.20947546944294e-05, 9.62973878475845e-07, 0.00710967831313203,
26.9833955280036, 0.00265697432110539, 1.41814003567946, 0.261340025051291,
0.00159083508412152, 9.55044905589291e-06, 0.0122931632086495,
8.54789134364452e-06, 2.01899938950824e-05, 1.55354988683742e-06,
0.000441285511108929, 0.000353500530366103, 0.125347054487635,
109.440278770173, 2.03304264082645e-05, 2.01899938950824e-05,
0.000148628664387571, 2.89902659683517e-06, 207.073625180606,
3.52469070261441e-07, 3.15047327017105e-06, 0.639049681601525,
2.11937734339159e-05, 0.484309094613314, 0.0126387710681522,
0.000124981311087457, 0.010701820155981, 0.00520458916051572,
0.002548740132205, 6.70653961877279e-06, 1.1372650836283e-06,
0.0028674817110041, 6.38196191847228, 0.00104230990042965, 2.77791027153022,
0.385285554179204, 3.23552539344696, 0.00129215960928528, 3313.17800288969,
0.42454812322342, 0.427501088945987, 0.0252775421363044, 1.3790172222154e-05,
0.000499925244349826, 0.575943821174679, 3.66456124110476e-05,
0.000979273863184647, 1.71186456807568e-06, 0.000506903940694852,
3.95489796579998e-05, 7.60789146241221e-07, 5.53083255055159e-07,
0.000283178626588241, 5.68632541814152e-07, 89.5114292952616,
2.15183665744117e-06, 9.48447928546097e-06, 1.10616651011032e-06,
6.83831307491562e-05, 0.000231612381626088, 0.361984543094889,
5.91197625260395e-05, 0.000979273863184647, 2.83936549218472e-06,
0.000979273863184647, 5.11112358098405e-05, 1.714153924998e-07,
5.19634300333657e-07, 3.36257994807117e-06, 0.482299092292068,
1.40214978558205e-05, 0.00847835446782661, 5.84677257215999e-05,
0.00674484030136259, 0.00483589957358377, 0.0017456741452281,
6.45120458509457e-06, 6.32689066217975e-07, 0.00245170310797391,
9.30496033238278, 0.000922604532223834, 1.94261499108326, 0.348202870167258,
0.506277403675245, 0.000285939985649123, 0.000340041865397713,
0.11809338012465, 60.884369685235, 2.29364239206782e-05, 1.59952159960469e-05,
0.000213718586351138, 2.65657707341963e-06, 3635.65603745587,
1.08786283557826e-07, 83.9815202938853, 211.131788444181, 1.73147313103931,
0.162893393670412, 6347.61978641754, 1.56049096034741, 0.532923368033971,
0.651573574681646, 22.0392007421302, 0.05154584678813, 85997.0767809387,
2.10234581817541, 1994.76074197656, 17462.8329237372, 1.76785506212734,
49735.9012814537, 1.57134503333516, 340.615434516655, 3.73730938753272,
2.07340220203944, 0.974004268543241, 53.8920290309386, 28.8800232787977,
0.0604547706008708, 6.41744933081988, 1.9615580079771, 1.57750051307367e-05,
2.09600255345096e-05, 0.000200793473806753, 1.29196641682183e-06,
179.519904082227, 2.39744324779145e-07, 2.44454941589392e-06,
0.492433221447773, 1.07746460295468e-05, 0.437695664847132, 0.00947275639891981,
9.69768554804815e-05, 0.0056325346541415, 0.00470366164543522,
0.00172164093341244, 6.91422987569681e-06, 8.82439067876674e-07,
1.57134503333516, 1.79253339913881, 2.00277451142267, 1.74351647907412,
2.66105808216138, 0.90250072746243, 2.059080166868, 1.50733490955838,
1.3966785324674, 1.61552155521922, 0.384751805040216, 1.53900722016086,
1.68412590721683, 0.000995700862302919, 9.18683915124066e-06,
0.00490340621594781, 9.51081233425213e-06, 1.64449027258861e-05,
1.32828853670982e-06, 0.000283964853893518, 0.000480891817820092,
0.103521332666818, 96.202334596196, 1.6958399292663, 0.98077900398855,
0.000159075579756261, 2.31658561238929, 1.62675839626425, 2.23767420207142,
1.67249279982813, 1.53900722016086, 1.51781925297405, 0.717972255311719,
1.08072540203935, 1.6958399292663, 1.74351647907412, 1.32133840565826,
0.0210213626331535, 1.87597483406766e-05, 4.9165300967331e-05,
0.00253816223135828, 5.84822979360013, 0.000929021754230271,
2.31017156910716, 0.278934830581241, 2.84415482117455, 0.00100262650949219,
2661.45599990874, 0.357992185300285, 0.37579036951639, 1.42602571736414,
1.90791910109511, 1.38703096913138, 0.353063601096188, 2.84344613435294e-05,
0.00277749494255326, 1.32828853670982e-06, 0.00108958918195797,
9.25073867082013e-06, 1.4059026149049e-07, 4.29154362580066e-07,
0.000537294242854559, 8.10925044524043e-06, 0.020165038913309,
9.91469621624329e-06, 1.63313094852695e-05, 8.58308725160133e-07,
1.43594451062343, 0.312515575646302, 34.1070955541741, 2339.52511354582,
11.0962477530511, 8.17942824487938, 1.68412590721683, 0.418123199957032,
804.528657067602, 0.679243142274472, 10.5707072452661, 6.5522935828786,
1.68412590721683, 1.38703096913138, 1.49692298679269, 1.69583992926629,
2.16145080407871, 2.67956720485568, 1.3966785324674, 1.53900722016086,
1.70763542878249, 0.921464186198703, 3.32188009636358, 7.57896056479413,
2.34183669433728e-05, 0.000352033415883844, 0.28087497575791,
4.58728478413563e-05, 0.0007598488052299, 1.48407969771465e-06,
0.0223745115812679, 1.15479796826903e-05, 1.33006491938229e-07,
4.03200286568411e-07, 1.47631440568283, 1.75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, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Endoderm",
"Ectoderm"), class = "factor")), .Names = c("Classification",
"value", "listElement"), row.names = c(NA, -270L), class = "data.frame")
Running the same code as above:
boxData$temp <- paste(substr(boxData$Classification,1,6),
as.character(boxData$listElement))
ggplot(boxData, aes(reorder(boxData$temp, value, median),value, fill=Classification))+
geom_boxplot()+
scale_y_log10()+
ylab("Fold Expression Change")+
xlab("Gene Classification")+
theme(axis.text.x=element_text(angle=90, hjust=1, size=6))+
facet_wrap(~listElement, scales='free', ncol=1)+
scale_x_discrete(labels=setNames(as.character(boxData$Classification), boxData$temp))
gives a strange-looking graph:
This graph should look the same as the first graph, just with two facets rather than three. If I don't try to reorder the values by median, this graph plots fine. I've fiddled with a number of things, but can't seem to fix this issue. I'm sure I've made a stupid mistake somewhere, but can't seem to find it.
Any help would be greatly appreciated!

It looks to me that you are reordering the factor "temp" without releveling the dataset. What about bringing the ordering operation outside the ggplot call?
boxData$temp <- paste(substr(boxData$Classification,1,6),
as.character(boxData$listElement))
fac <- with(boxData, reorder(temp, value, median, order = TRUE))
boxData$temp <- factor(boxData$temp, levels = levels(fac))
ggplot(boxData, aes(temp,value, fill=Classification))+
geom_boxplot()+
scale_y_log10()+
ylab("Fold Expression Change")+
xlab("Gene Classification")+
theme(axis.text.x=element_text(angle=90, hjust=1, size=6))+
facet_wrap(~listElement, scales='free', ncol=1)+
scale_x_discrete(labels=setNames(as.character(boxData$Classification), boxData$temp))
This is what you would expect, right?

Related

getting Error in svd(X) : infinite or missing values in 'x' when using summary of regression model

I am getting an error
Error in svd(X) : infinite or missing values in 'x'
while doing summary of ordinal regression model. This is my code ..
library(MASS)
a <- dget('dput.txt')
lep <- polr(bmicat2 ~ Leptin, data = a,Hess = TRUE)
summary(lep)
Error in svd(X) : infinite or missing values in 'x'
sample data is given to replicate the error. Can someone please help.
structure(list(bmicat2 = structure(c(1L, 3L, 2L, 1L, 1L, 1L,
1L, 1L, 3L, 3L, 3L, 3L, 3L, 1L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 1L,
3L, 3L, 1L, 1L, 2L, 1L, 2L, 2L, 3L, 1L, 1L, 1L, 1L, 1L, 2L, 3L,
2L, 1L, 1L, 3L, 3L, 2L, 1L, 1L, 1L, 2L, 1L, 3L, 1L, 3L, 1L, 1L,
1L, 2L, 1L, 3L, 2L, 1L, 1L, 2L, 1L, 3L, 1L, 1L, 1L, 3L, 1L, 3L,
3L, 3L, 2L, 3L, 1L, 3L, 3L, 3L, 2L, 2L, 1L, 2L, 2L, 1L, 3L, 1L,
1L, 1L, 2L, 2L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 2L, 3L, 1L, 2L, 1L,
2L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 3L, 1L, 1L, 2L, 2L, 2L, 1L, 3L,
3L, 3L, 3L, 3L, 2L, 3L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 3L, 1L, 1L, 1L, 1L, 2L, 3L, 2L,
2L, 1L, 1L, 1L, 3L, 2L, 1L, 3L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 3L,
1L, 1L, 1L, 3L, 1L, 1L, 1L, 3L, 1L, 3L, 3L, 1L, 1L, 1L, 1L, 3L,
1L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 2L, 1L, 2L, 1L, 3L, 2L, 1L, 1L,
1L, 3L, 1L, 1L, 2L, 2L, 3L, 1L, 2L, 1L, 1L, 1L, 3L, 1L, 1L, 3L,
1L, 3L, 1L, 3L, 3L, 3L, 1L, 2L, 1L, 3L, 1L, 3L, 2L, 1L, 3L, 3L,
1L, 2L, 3L, 3L, 1L, 2L, 1L, 3L, 1L, 3L, 1L, 1L, 3L, 1L, 1L, 1L,
1L, 1L, 1L, 3L, 1L, 3L, 3L, 1L, 1L, 1L, 3L, 2L, 3L, 2L, 1L, 1L,
3L, 3L, 2L, 1L, 3L, 2L, 3L, 3L, 3L, 2L, 1L, 3L, 3L, 3L, 2L, 1L,
3L, 1L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L,
3L, 3L, 1L, 3L, 3L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 3L, 1L, 3L, 3L,
2L, 3L, 2L, 3L, 3L, 1L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 1L, 3L,
1L, 1L, 1L, 3L, 1L, 2L, 3L, 1L, 1L, 3L, 2L, 1L, 3L, 3L, 2L, 2L,
1L, 1L, 3L, 2L, 3L, 3L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 3L,
3L, 3L, 2L, 1L, 1L, 3L, 3L, 1L, 2L, 3L, 3L, 1L, 3L, 3L, 1L, 1L,
1L, 3L, 1L, 3L, 3L, 2L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 1L, 1L, 1L,
3L, 2L, 2L, 2L, 1L, 3L, 1L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L,
1L, 1L, 1L, 1L, 2L, 1L, 3L, 1L, 1L, 1L, 3L, 2L, 2L, 2L, 1L, 3L,
1L, 1L, 3L), .Label = c("Normal", "Overweight", "Obesity"), class = "factor"),
Leptin = c(47710.88, 200022.04, 161067.35, 55561.76, 100728.06,
69783.61, 54981.01, 58801.34, 128313.05, 157378.46, 292366.57,
121608.04, 206046.88, 54981.01, 154969.33, 516791.75, 104766.73,
440134.48, 286576.47, 343513.87, 40020.2, 30077.63, 359266.48,
290381.41, 23005.7, 48080.73, 134741.37, 114631.03, 49644.25,
139956.69, 138242.54, 19862, 64541.08, 57119.32, 115382.48,
7238.99, 154969.33, 82321.93, 85406.54, 19170.47, 57208.08,
277488.74, 290791.3, 206703.97, 25333.82, 20134.62, 32823.3,
231036.03, 111986.18, 352190.59, 128041.35, 185025.96, 63451.72,
143404.56, 71163.46, 252067.35, 46223.39, 185077.75, 172339.07,
41381.36, 91498.49, 233969.82, 24245.94, 248133.29, 145890.48,
196431.01, 146690.84, 218617.65, 151333.68, 245695.08, 336242.88,
266936.45, 64105.63, 301181.31, 150192.02, 253863.48, 314169.03,
406059.04, 68228.37, 335171.04, 37547.56, 123713.8, 75034,
45708.91, 67449.43, 15920.57, 38444.37, 19170.47, 174853.97,
236689.18, 22879.68, 34599.46, 57562.83, 177486.58, 244481.84,
122637.48, 58094.2, 82921.65, 382788.21, 119733.17, 64192.75,
8787.33, 17146.98, 21986.45, 13077.71, 18320.19, 119777.74,
61615.67, 5708.97, 24307.05, 244118.62, 10780.13, 12158.23,
80265.64, 70215.06, 122189.66, 48219.23, 156702.5, 128313.05,
115072.95, 152956.29, 107776.73, 108914.21, 85835.09, 13608.28,
24853.42, 58359.56, 29967.69, 168944.14, 22435.55, 67709.18,
17444.89, 51058.87, 21072.27, 34702.75, 9711.01, 43870.71,
113571.74, 26863.91, 294914.16, 15920.57, 23381.51, 309409.6,
19587.14, 99905.3, 79494.37, 90768.21, 131129.25, 411527.63,
132269.4, 83735.58, 92014.19, 57030.54, 62578.38, 131676.19,
238711.8, 48080.73, 429691.15, 88750.76, 32770.45, 163022.26,
98045.93, 8421.27, 113659.95, 27210.74, 421265.4, 225005.8,
39431.91, 18748.27, 224660.83, 13695.33, 11186.36, 42727.62,
863581.67, 18031.36, 250895.16, 326547.74, 69351.93, 34288.82,
64932.66, 23381.51, 392858.01, 32399.47, 176370.64, 31651.9,
17592.65, 93304.24, 71938.68, 297130.98, 58624.7, 311565.88,
143685.29, 204518.07, 28689.43, 612308, 119688.61, 116888.21,
60738.48, 274462.8, 307122.48, 202886.86, 119777.74, 194409.2,
259555.37, 479766.12, 97527.66, 177029.67, 17146.98, 70560.06,
50922.4, 213003.8, 142470.09, 26747.8, 235563.59, 49460.99,
185181.36, 27210.74, 156220.34, 284284.42, 254982.61, 67059.61,
46736.22, 97657.21, 399497.2, 13433.03, 385197.12, 143685.29,
46503.31, 333111.93, 228589.14, 40117.95, 86563.73, 459114.82,
334559.84, 39824.45, 90295.84, 19309.96, 25333.82, 15604.37,
548683.37, 13954.22, 63974.92, 283344.56, 47061.73, 14794.69,
56852.91, 63320.83, 21335.74, 18176.13, 44060.31, 31436.88,
779337.47, 177842.32, 15683.81, 1804.18, 18031.36, 150572.24,
69956.22, 353788.11, 42823.25, 25927.76, 23131.34, 351871.83,
130355.47, 48034.54, 9711.01, 296020.99, 77994.24, 106641.08,
NA, 68876.79, 64323.41, 37947.12, 166071.05, 239189.29, 376318.03,
132041.15, 48818.15, 209454.17, 25572.25, 232324.09, 142750.23,
34185.02, 21204.24, 6040.1, 5708.97, 252190.95, 129219.75,
50922.4, 97786.76, 117464.95, 84978.04, 15122, 6356.95, NA,
299220.74, 28801.64, 535105.27, 421922.32, 9486.52, 159801.65,
139492.77, 40410.71, 28011.68, 67189.58, 10780.13, 173997.11,
15283.91, 192081.41, 169590.94, 29747.24, 57961.45, 55606.38,
351712.55, 157233.52, 117553.73, 201046.58, NA, 204409.11,
468179.87, 201640.99, 374968.45, 330911.94, 153817.84, 45098.7,
83050.16, NA, 20134.62, 20606.55, 328498.24, 22115.29, 40313.21,
196751.22, 6356.95, 8042.41, 252005.56, 124522.47, 9711.01,
168745.34, 110580.08, 78722.96, 104897.35, 43728.34, 20270.11,
339321.01, 170488.25, 55829.38, 173292.85, 29967.69, 5708.97,
30132.53, 12715.53, 180648.71, 146219.86, 33716.28, 85835.09,
110404.53, 327146.88, 259303.38, 164396.3, 206156.31, 21204.24,
105158.65, 152478.41, 327897.07, 29025.44, 36237.65, 426358.52,
265525.58, 52464.02, 287117.75, 658217.42, 67709.18, 107645.6,
46829.29, 186790.78, 68920, 363915.23, 269385.74, 126324.01,
146361.1, 153243.28, 101161.4, 318839.47, 132223.74, 96190,
143966.19, 162141.4, 63495.34, 35371.14, 261070.81, 197071.7,
240146.08, 73100.38, 63713.39, 248622.82, 92616.07, 163120.25,
95026.25, 266807.98, 153434.72, 145937.52, 127950.82, 376487.04,
81208.15, 311998.55, 41767.47, 59595.08, 13256.19, 35011.88,
99083.27, 47571.98, 174450.51, 8296.48, 35524.66, 68747.15,
214064.04, 127272.35, 70603.17, 99256.27, 19862, 145373.38,
184560.15, 57828.63, 115426.71)), row.names = c(NA, -425L
), class = c("tbl_df", "tbl", "data.frame"))
It is an issue of lep$Hessian having NA values. If you do this:
lep <- polr(bmicat2 ~ Leptin, data = a,Hess = TRUE)
lep$Hessian[1,1]<-0
lep$Hessian[1,2]<-0
lep$Hessian[1,3]<-0
lep$Hessian[2,1]<-0
lep$Hessian[3,1]<-0
summary(lep)
You do not have any problems but the output from lep and summary(lep) are pretty much the same, I think. Is it the imputation of 0 to missing values in the Hessian that disturbing?

How to randomly change 50% of a column observations based on another column condition?

I'm analyzing a survey and I need to do an interaction.plot() between variable disclosure_1 and TYPE_1 to see how they affect a third variable ADTRUST.
The survey randomly showed a different scenario to each participant. DISCLOSURE_1 is the code to indicate the type of disclosure that was shown to a respondent (B = Before, D = During, A = After, N = None).
TYPE_1 indicates the terminology used (DF = Deepfake, SM = Sythetic Media).
When creating the survey I dumbly only used DF for N because I thought there was no need to create an SM scenario if there was no disclosure shown (so no difference in terminology used). It still makes no sense logically, but when plotting the interaction plot the variable N does not appear. And since the study wants to analyze:
how disclosure impacts ADTRUST
how disclosure positioning impacts ADTRUST
how different terminology used in disclosure impact ADTRUST
I need to randomly substitute 50% of the observations with SM instead of DF under TYPE_1 but ONLY if the column DISCLOSURE_1 is == N.
I have no clue how to do that. Could somebody please help?
NOTE!!!! The structure is part of a bigger dataset. the dput was only done only for [25:26], so keep in mind I need to be able to precisely select the columns in the code.
Thank youu
structure(list(DISCLOSURE_1 = structure(c(4L, 3L, 1L, 3L, 1L,
1L, 4L, 3L, 4L, 3L, 4L, 1L, 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, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L,
2L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L,
2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L,
1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L,
2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L,
1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L,
2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L), .Label = c("DF",
"SM"), class = "factor")), row.names = c(NA, -367L), class = c("tbl_df",
"tbl", "data.frame"))
With data as your data.frame, this will replace exactly half (rounded down) of the N's with DF with SM:
blnN <- data$DISCLOSURE_1 == "N" & data$TYPE_1 == "DF"
data$TYPE_1[sample(which(blnN), sum(blnN)/2)] <- "SM"
If the 50% requirement is approximate, you can use runif() > 0.5
library(dplyr)
table(df)
TYPE_1
DISCLOSURE_1 DF SM
A 52 51
B 52 53
D 55 51
N 53 0
mut <- df |>
mutate(TYPE_1 = ifelse(DISCLOSURE_1 == "N" &
TYPE_1 == "DF" &
runif(n()) > 0.5,
"SM",
as.character(TYPE_1)))
table(mut)
TYPE_1
DISCLOSURE_1 DF SM
A 52 51
B 52 53
D 55 51
N 27 26

Why the energy distance function give me null result?

As mention here https://cran.r-project.org/web/packages/energy/energy.pdf
the e.dist returns Returns the E-distances (energy statistics) between clusters.
And as inputs it accepts data matrix of pooled sample or Euclidean distances.
I want to compute the e-distance between 100 observations of my data set.
Look what I did:
> disteuc<-dist(DATABASE,method = "euclidean")
> edist(disteuc,sizes=100)
dist(0)
Why I get null value ??
This is the first 100 rows of my data set:
> dput(DATABASE[1:100,])
structure(list(TYPE_PEAU = c(2L, 2L, 3L, 2L, 2L, 2L, 2L, 4L,
3L, 2L, 2L, 2L, 2L, 1L, 4L, 2L, 2L, 2L, 4L, 2L, 3L, 3L, 2L, 2L,
2L, 2L, 2L, 4L, 3L, 4L, 2L, 2L, 2L, 2L, 4L, 2L, 1L, 2L, 2L, 2L,
2L, 4L, 3L, 2L, 4L, 2L, 1L, 2L, 2L, 2L, 3L, 1L, 2L, 4L, 2L, 2L,
3L, 4L, 2L, 2L, 2L, 2L, 2L, 4L, 2L, 2L, 2L, 4L, 2L, 4L, 2L, 4L,
3L, 3L, 2L, 2L, 2L, 2L, 4L, 4L, 2L, 2L, 4L, 2L, 2L, 2L, 4L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 4L, 2L, 2L, 2L, 2L, 2L), SENSIBILITE = c(3L,
2L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 3L, 3L, 3L,
1L, 3L, 3L, 1L, 3L, 2L, 2L, 3L, 3L, 3L, 1L, 3L, 3L, 2L, 1L, 3L,
1L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"ALLERGIES", "MAINS", "PEAU_CORPS", "INTERET_ALIM_NATURELLE",
"INTERET_ORIGINE_GEO", "INTERET_VACANCES", "INTERET_ENVIRONNEMENT",
"INTERET_COMPOSITION", "AGE_INTERVAL", "ATTENTE_BEAUTE_1", "ATTENTE_BEAUTE_2",
"MILIEU_VIE", "PROFIL_SELECTIONNE", "NOMBRE_ACHAT", "NOMBRE_CADEAU"
), row.names = c(NA, 100L), class = "data.frame")
>
You are only specifying a cluster size, if you have 100 data and they are all in the same cluster there are no distances to other clusters.
> edist(disteuc,sizes=100)
dist(0)
> edist(disteuc,sizes=c(10, 90))
1
2 42.51959
> edist(disteuc,sizes=c(10, 40, 50))
1 2
2 44.32714
3 39.80484 35.26888

How to add significance letters (anova) to ggplot geom_bar with facet wrap

When I make a barplot with significance letters from anova above the bars, I use following code:
anova_NDW_geel<-aov(nodule_dry_weight~treatment,inoculatieproef_geel_variety2)
HSD_NDW_geel <- HSD.test(anova_NDW_geel,"treatment",alpha=0.05,group=TRUE)$groups
HSD_NDW_means_geel <- HSD.test(anova_NDW_geel,"treatment",alpha=0.05,group=TRUE)$means
HSD_NDW_means_geel <- HSD_NDW_means_geel[order(-HSD_NDW_means_geel$nodule_dry_weight),]
p_HSD_NDW_geel <- ggplot(aes(x=treatment, y=NDW_mean_geel, width=0.6), data=inoculatieproef_mean_geel)+
geom_bar(stat="identity", data=HSD_NDW_geel, aes(x=trt, y=means), fill="gray40")+
geom_text(data=HSD_NDW_geel, aes(x=trt, y=means, label=M), size=5, vjust=-1, hjust=1)+
ggtitle("Zand")+
ylab("Droog gewicht wortelknolletjes (g)")+
xlab("Behandeling")+
geom_errorbar(aes(ymin=NDW_mean_geel-NDW_sd_geel,ymax=NDW_mean_geel+NDW_sd_geel),
position=position_dodge(width=0.5),width=0.1,size=0.3)+
theme_bw() +
theme(axis.line = element_line(colour="black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank())+
scale_y_continuous(expand = c(0, 0))+
theme(axis.text.x = element_text(angle = 0, hjust = 1, vjust = 0.5))+
theme(text = element_text(size=12))
which results in following graph: http://i.stack.imgur.com/bZidZ.png
This is probably not the best way to do this and when I want to add the letters to the barplots with facet wrap.
Here is a sample of the data I want to make a facet wrap with significance letters with:
structure(list(treatment = structure(c(1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L,
7L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, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("2014",
"2015"), class = "factor"), nodule_dry_weight = c(0, 0.0467,
0.0328, 0.0885, 0.0081, 0.1086, 0.0788, 0.0267, 0, 0.0128, 0.0143,
0.0333, 0.006, 0.098, 0.0286, 0.011, 0, 0.0627, 0.0769, 0.0784,
0.023, 0.1504, 0.1026, 0.0254, 0, 0.0597, 0.0158, 0.0354, 0.0226,
0.3261, 0.0436, 0, 0, 0.0203, 0.0469, 0.0904, 0.1593, 0.0836,
0.056, 0.0037, 0, 0.0534, 0.0901, 0.0435, 0.0248, 0.0435, 0.0279,
0.0029, 0, 0.0545, 0.038, 0.0991, 0.0099, 0.1453, 0.1096, 0.0272,
0, 0.0319, 0.0624, 0.0508, 0.0415, 0.11, 0.0079, 0, 0, 0.1257,
0.1242, 0.2899, 0.024, 0.2175, 0.2979, 0.0396, 0, 0.1583, 0.2935,
0.2541, 0.1027, 0.4196, 0.2059, 0.0396, 0, 0.0891, 0.167, 0.0907,
0.2153, 0.3063, 0.2921, 0.0528, 0, 0.0928, 0.2109, 0.1514, 0.0821,
0.3607, 0.0996, 0.0069, 0, 0.0685, 0.3109, 0.1862, 0.0393, 0.286,
0.3418, 0.0459, 0, 0.0765, 0.3486, 0.3988, 0.1155, 0.6341, 0.3653,
0.039, 0, 0.0766, 0.3112, 0.1988, 0.05, 0.2856, 0.34, 0.0862,
0, 0.2621, 0.1146, 0.393, 0.1644, 0.3415, 0.1343, 0.019, 0, 0.0976,
0.1853, 0.0691, 0.0248, 0.1764, 0.1244, 0.1525, 0, 0.1529, 0.1069,
0.2833, 0.0204, 0.2966, 0.2371, 0.1464, 0, 0.0691, 0.2094, 0.1633,
0.0264, 0.1344, 0.0694, 0.1175, 0, 0.1783, 0.1434, 0.2136, 0.0873,
0.19, 0.1683, 0.1927, 0, 0.0571, 0.0599, 0.1061, 0.0244, 0.1256,
0.0894, 0.0123, 0, 0.1696, 0.1046, 0.2164, 0.0939, 0.1552, 0.2942,
0.1652, 0, 0.0844, 0.102, 0.0227, 0.025, 0.0654, 0.1234, 0.0702,
0, 0.0979, 0.1246, 0.0958, 0.0867, 0.1104, 0.1969, 0.227, 0,
0.3704, 0.4727, 0.2527, 0.2078, 0.3377, 0.308, 0.1293, 0, 0.2417,
0.3744, 0.2916, 0.1773, 0.433, 0.2446, 0.1382, 0, 0.4718, 0.4271,
0.4882, 0.1799, 0.4178, 0.518, 0.3915, 0, 0.3421, 0.3804, 0.2112,
0.4292, 0.3829, 0.1315, 0.2719, 0, 0.3197, 0.6867, 0.414, 0.3112,
0.2914, 0.4994, 0.369, 0.0256, 0.1494, 0.5577, 0.2538, 0.3854,
0.4151, 0.544, 0.4009, 0, 0.5208, 0.2962, 0.4175, 0.2689, 0.3374,
0.5075, 0.3601, 0, 0.704, 0.4631, 0.4573, 0.154, 0.5087, 0.4319,
0.4155)), .Names = c("treatment", "block", "position", "variety",
"location", "year", "nodule_dry_weight"), row.names = c(NA, -256L
), class = "data.frame")
I use following code for my graph with facet wrap:
inoculatieproef <- inoculatieproef %>%
group_by(treatment, location, variety, year) %>%
mutate(NDW_mean = mean(nodule_dry_weight),
NDW_sd = sd(nodule_dry_weight))
ggplot(data=inoculatieproef,aes(x=treatment, y=NDW_mean))+
facet_wrap(~location*variety*year,ncol=2)+
geom_bar(position="dodge", stat="identity")+
geom_errorbar(aes(ymin = NDW_mean - NDW_sd,
ymax = NDW_mean + NDW_sd),
width=0.1,size=0.3,
color = "darkgrey")+
theme_bw() +
theme(axis.line = element_line(colour="black"),
panel.grid.minor = element_blank(),
panel.background = element_blank())
How do I add on each barplot the significance letters (anova) in de the facet wrap graph?
No idea if the test fits your data distribution, but you can start with that:
library(tidyverse)
stat_pvalue <- dd %>%
group_by(location, variety, year) %>%
rstatix::t_test(nodule_dry_weight~treatment) %>%
filter(p < 0.05) %>%
group_by(location, variety, year) %>%
rstatix::add_significance("p") %>%
rstatix::add_y_position() %>%
mutate(y.position = seq(min(y.position), max(y.position),length.out = n())*1.1) %>%
ungroup()
ggplot(data=dd,aes(x=treatment, y=nodule_dry_weight))+
geom_boxplot() +
facet_wrap(~location + variety + year,ncol=2, scales = "free_y") +
ggpubr::stat_pvalue_manual(stat_pvalue, label = "p")

How to get the median line in bwplot thicker?

The following code is a minimal (for some value of minimal....) example that uses lattice to produce boxplots. But the median line on those boxplot is a) coloured and b) very thin. How to get them to be black and tick?
a71<-structure(list(n = structure(c(1L, 2L, 2L, 4L, 4L, 1L, 1L, 4L,
2L, 1L, 1L, 2L, 2L, 4L, 2L, 2L, 3L, 4L, 1L, 2L, 2L, 3L, 2L, 2L,
2L, 4L, 3L, 3L, 4L, 2L, 4L, 2L, 1L, 3L, 2L, 3L, 4L, 1L, 4L, 1L,
3L, 3L, 2L, 1L, 1L, 3L, 3L, 1L, 2L, 4L, 3L, 2L, 3L, 1L, 4L, 1L,
4L, 2L, 3L, 4L, 4L, 4L, 1L, 3L, 3L, 3L, 4L, 2L, 2L, 2L, 4L, 4L,
4L, 1L, 4L, 3L, 2L, 2L, 4L, 4L, 3L, 2L, 2L, 2L, 1L, 2L, 3L, 3L,
3L, 1L, 3L, 3L, 4L, 1L, 3L, 2L, 1L, 3L, 1L, 2L), .Label = c("100",
"200", "400", "800"), class = "factor"), g = structure(c(3L,
3L, 1L, 3L, 1L, 3L, 2L, 1L, 1L, 3L, 1L, 2L, 3L, 1L, 2L, 2L, 1L,
3L, 1L, 2L, 3L, 2L, 2L, 2L, 3L, 1L, 1L, 3L, 3L, 2L, 1L, 1L, 3L,
1L, 3L, 3L, 1L, 2L, 2L, 2L, 2L, 3L, 2L, 3L, 3L, 1L, 3L, 3L, 1L,
1L, 1L, 2L, 3L, 1L, 3L, 1L, 3L, 3L, 1L, 2L, 1L, 2L, 2L, 1L, 3L,
3L, 1L, 3L, 2L, 3L, 1L, 3L, 1L, 1L, 3L, 3L, 2L, 3L, 3L, 3L, 1L,
3L, 3L, 2L, 3L, 3L, 2L, 2L, 2L, 3L, 2L, 2L, 3L, 1L, 2L, 3L, 3L,
3L, 1L, 3L), .Label = c("0", "0.5", "1"), class = "factor"),
cr = structure(c(1L, 2L, 3L, 1L, 3L, 3L, 2L, 1L, 2L, 3L,
3L, 2L, 2L, 3L, 2L, 2L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 1L, 1L,
3L, 3L, 3L, 1L, 3L, 1L, 1L, 1L, 2L, 1L, 1L, 3L, 2L, 3L, 1L,
3L, 2L, 2L, 2L, 3L, 2L, 3L, 1L, 1L, 2L, 1L, 2L, 2L, 3L, 1L,
1L, 1L, 1L, 3L, 3L, 2L, 3L, 1L, 3L, 3L, 3L, 3L, 1L, 1L, 1L,
1L, 1L, 2L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 3L, 3L, 2L, 1L, 2L,
2L, 2L, 2L, 3L, 2L, 2L, 1L, 3L, 2L, 1L, 3L, 1L, 1L, 2L, 2L
), .Label = c("-0.4", "0", "0.4"), class = "factor"), bias = c(0.0162558992812201,
0.138354243932496, 0.0205686041691062, 0.269714433604472,
0.381044037439145, 0.0869422119950729, 0.331379037601084,
0.686894150152472, 0.0140922903231885, 0.225078933454863,
0.554444988164574, 0.076032683077827, 0.335284040888653,
0.0630810396519646, 0.358402154233125, 0.260940142571834,
0.141353291599136, 0.0220267076189838, 0.242149484071382,
0.278319984858078, 0.193105829691662, 0.0259815643559331,
0.318504899459259, 0.00277002060524357, 0.212681621053374,
0.418358846098857, 0.358916156777489, 0.438248724241505,
0.194398889511096, 0.2266870834128, 0.144338808446284, 0.149227951210927,
0.268111328952192, 0.123265441389974, 0.0376832357983068,
0.0353605481767078, 0.021227873083535, 0.0385614926552725,
0.130640111978654, 0.161865326447675, 0.174151298764213,
0.292085797406362, 0.198391364913347, 0.0779507859721407,
0.0045571464157577, 0.114734038438965, 0.0469613758623325,
0.64238405800387, 0.74508519247034, 0.0251182457091362, 0.217835062247358,
0.131159910126724, 0.130034859007596, 0.222418419987533,
0.0861715693619894, 0.185660520258661, 0.0940670543815277,
0.105680179626893, 0.215966730684923, 0.109008340760604,
0.0474735195202623, 0.192326789813641, 0.022147195644035,
0.277372858009381, 0.237574293593955, 0.123383946121193,
0.46406480500022, 0.123698482002945, 0.671442441453945, 0.0406004813894845,
0.260472754754191, 0.0151116521560003, 0.0422855023583402,
0.0405517218780402, 0.0441583998205882, 0.0958995639409343,
0.37588506579263, 0.098494760958735, 0.0928763466294421,
0.111205748449328, 0.413083543393392, 0.0138839674143682,
0.22407421093074, 0.72309883706409, 0.423231501875638, 0.141932050342199,
0.133808548118004, 0.331500621801688, 0.127652280721512,
0.132083126730013, 0.261864564503826, 0.208243130464985,
0.18657049493156, 0.333701537602998, 0.404884075502013, 0.470789398932934,
0.115008599462104, 0.177984001517338, 0.331717679106776,
0.0862418839846533), group = structure(c(3L, 2L, 2L, 3L,
1L, 3L, 3L, 2L, 2L, 1L, 3L, 2L, 2L, 2L, 1L, 3L, 2L, 3L, 1L,
3L, 1L, 2L, 1L, 3L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 3L, 1L, 1L,
3L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 3L, 1L, 2L,
3L, 3L, 3L, 1L, 1L, 3L, 2L, 3L, 1L, 1L, 2L, 2L, 2L, 2L, 1L,
2L, 1L, 1L, 1L, 3L, 2L, 2L, 1L, 1L, 3L, 3L, 3L, 2L, 1L, 3L,
3L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 3L, 3L, 1L, 1L, 2L, 3L,
1L, 1L, 3L, 2L, 1L, 3L), .Label = c("1", "2", "3"), class = "factor")), .Names = c("n",
"g", "cr", "bias", "group"), row.names = c(8721L, 6970L, 6686L,
9624L, 352L, 10545L, 7505L, 4216L, 6170L, 3309L, 10429L, 4302L,
5602L, 5680L, 1530L, 9234L, 5007L, 8004L, 721L, 10038L, 502L,
4891L, 2946L, 8502L, 622L, 1972L, 2403L, 3383L, 5880L, 1038L,
4756L, 9506L, 2169L, 1023L, 8506L, 6239L, 7768L, 3221L, 9536L,
5981L, 1507L, 4883L, 414L, 3117L, 3993L, 1923L, 9143L, 2673L,
4430L, 9520L, 9363L, 10602L, 95L, 1141L, 9660L, 4285L, 10704L,
154L, 531L, 6440L, 4876L, 7052L, 4397L, 3375L, 5075L, 1295L,
2620L, 334L, 9510L, 4690L, 4288L, 3576L, 2248L, 7693L, 8820L,
8135L, 4026L, 1906L, 10164L, 8616L, 423L, 5290L, 418L, 6486L,
4485L, 7042L, 955L, 2215L, 9031L, 8049L, 2323L, 1627L, 4212L,
8689L, 439L, 2590L, 8649L, 5447L, 1957L, 10570L), class = "data.frame")
library(lattice)
cl<-c('red','green','blue')
mypanel<-function(...){
panel.bwplot(...,pch="|",col="black",cex=4,fill=cl)
}
o1<-bwplot(a71$bias~a71$group|a71$cr*a71$g,type=c("l","g"),ylim=c(0,1),panel=mypanel)
plot(o1)
By changing some of the parameters of box.rectangle (a lattice-specific graphical parameter), you can manipulate the lines (including the median line) surrounding each of the box plots. This will change all the lines around the boxes, however, not just the median line.
myPars <- list(box.rectangle = list(lwd = 2, col = "black"))
lwd changes the line width (thickness). colchanges the color of the lines. Then pass this list to the par.settings argument in bwplot.
o1 <- bwplot(a71$bias ~ a71$group | a71$cr * a71$g,
type = c("l", "g"), ylim = c(0, 1), panel = mypanel,
par.settings = myPars)
plot(o1)
To see all of the parameters associated with box.rectangle, use
trellis.par.get("box.rectangle")
OP is happy with all lines thicker by #BenBarnes, but for completeness, it is possible to just thicken the median line. Using the fact that box.width defaults to 1/2:
bwplot(a71$bias~a71$group|a71$cr*a71$g,type=c("l","g"),ylim=c(0,1),
panel=function(x,y,...){
panel.bwplot(x,y,...,pch="|",col="black",cex=4,fill=cl)
medy <- by(y,list(x),median)
xx <- sort(unique(as.numeric(x)))
panel.segments(xx-.25,medy,xx+.25,medy,lwd=2)
}
)

Resources