I'm trying plotting some graphs via the following loop:
library(ggstatsplot)
for (i in 5:ncol(df)) {
print(ggbetweenstats(df,
x = 'D', y = colnames(df[i]),
palette = 'npg',
effsize.type = 'eta',
type = "parametric", # ANOVA or Kruskal-Wallis
var.equal = TRUE, # ANOVA or Welch ANOVA
plot.type = "box",
pairwise.comparisons = TRUE,
pairwise.display = "significant",
centrality.plotting = FALSE,
bf.message = FALSE
))
}
However I'm keeping on getting back this error warning message:
Error: Only strings can be converted to symbols
For ensurance, I post below the dataset I'm working on:
> dput(df)
structure(list(A = 1:75, C = c("Maybe", "Maybe", "Maybe", "Maybe",
"Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe",
"Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe",
"Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe",
"Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe",
"Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe",
"Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe",
"Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe",
"Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe",
"Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe",
"Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe", "Maybe",
"Maybe"), D = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L), .Label = c("new_value_for_8", "new_value_for_6", "new_value_for_4"
), class = "factor"), E = c(988.368784828308, 988.856158671407,
996.004085290553, 999.685844324618, 1000.23888564896, 1005.03749946898,
999.786378084971, 997.039675082569, 998.028313183065, 997.168905747014,
1001.09291198164, 993.307008354785, 1004.23849942428, 1002.98988896299,
1003.55106999008, 1009.57481668809, 1005.41677956183, 1001.70676077155,
993.869639239065, 997.170442654021, 997.493277888883, 1000.52851758583,
1008.16418133488, 1001.88777321898, 992.264115311031, 990.169419475989,
993.025572998031, 1001.27327945355, 1002.11962397764, 1000.52429967762,
998.166892731571, 1000.65881048338, 999.738626511572, 1004.37524298634,
1000.6255556549, 1003.19617639836, 1000.04055175821, 996.706428965879,
999.618564942695, 994.265544900897, 993.887084764435, 997.542557651224,
1002.95352732001, 1000.5277212491, 1001.91803490989, 996.532966535325,
997.595615809563, 994.646255918378, 992.729713341507, 992.846778862404,
994.600444797032, 1002.65765002365, 1000.37249544151, 1006.24433066413,
1001.85698518142, 999.435545324196, 999.931476919632, 992.952173664209,
995.477367164094, 993.378653285675, 1004.56661945183, 1003.05859761336,
1002.02997952225, 993.89476037793, 999.47812876303, 996.021480043152,
997.387419796121, 995.860251713007, 996.078996748316, 995.368375334554,
995.632372813146, 993.289940301651, 995.772803883237, 999.770083493782,
994.302747991299), F = c(994.834756009939, 994.468875098246,
1000.62150212342, 1002.23100741241, 1003.96990710863, 1007.75899775608,
998.699806256246, 996.401009591011, 998.076594704249, 1002.19344184533,
1005.87900720863, 994.076210622421, 1002.44958531768, 1003.10043497883,
1001.65779442628, 1013.71182331817, 1006.86178446511, 1005.31481098188,
995.867593313022, 1000.16218228559, 1000.14208348451, 1005.42592103256,
1014.54963756727, 1004.52018125654, 997.593221945247, 994.616732970479,
998.442630353649, 1003.48359241788, 1004.23167123533, 1002.00051785325,
1001.48755216348, 1002.37269462739, 1001.30346907199, 1003.89476490635,
1001.87516303241, 1004.36353100771, 1001.94134174168, 997.778855524445,
999.984147937288, 997.238535900595, 996.483722875524, 1001.01799377569,
1001.74783962328, 1001.1303870722, 1002.16398550184, 996.684422052467,
998.160790249582, 993.932968362631, 991.843306038854, 990.769696036975,
995.644548584261, 1000.90630208122, 1000.45401759063, 1003.80236232314,
1004.03366573065, 1002.01859674451, 1000.83558931924, 995.319451176897,
998.79253832661, 994.495240005727, 1004.9659437387, 1004.13493084409,
1003.00187233307, 994.385347063973, 1000.54459607728, 994.795495894296,
999.967477941096, 997.719615789644, 997.986242971177, 998.345285530291,
999.380020106129, 995.517416599455, 998.577182214779, 1002.62315679074,
995.862634914667), G = c(1011.88022669726, 1012.10534266625,
1012.9554415821, 1015.09810043606, 1015.40462298842, 1016.67103699915,
1003.13771453335, 999.9107434841, 1002.15365554737, 1013.67789244066,
1014.38627383064, 1006.86762877786, 1007.47946451329, 1008.93405130319,
1008.45962311068, 1023.4166601996, 1015.18680921429, 1009.97183712754,
1006.2675210718, 1010.14219845841, 1010.63203584184, 1012.99980379135,
1020.70520656907, 1011.88521795707, 1015.78997960857, 1007.5072983389,
1014.30761724848, 1009.93797956768, 1010.76932384644, 1005.04681800218,
1005.16656503461, 1007.87875085817, 1002.29899409537, 1010.01354869538,
1005.48278706243, 1007.81908431469, 1008.64382513729, 1003.35777109534,
1003.47474629234, 1004.35678644331, 1003.47085321062, 1006.56231512355,
1004.93825547529, 1007.33985613752, 1006.819669006, 1006.54487921689,
1007.25872117706, 1001.10301223694, 999.143576420206, 999.112164307972,
999.068346627951, 1005.66176837543, 1002.29939831067, 1005.15548250667,
1006.59026080217, 1003.07417333636, 1001.80359068951, 1001.63892755704,
1003.85793371694, 1000.76931618851, 1010.70319073912, 1009.53278894638,
1008.01071628743, 1006.04891324235, 1011.19644538506, 1003.46633322373,
1014.4393884283, 1011.23395633535, 1007.74933708915, 1007.11820954752,
1007.39260082121, 1000.62743538132, 1009.1547320269, 1013.65590374333,
1007.14786907481), H = c(988.221495702721, 990.850727928741,
992.418094914622, 995.984841639886, 993.398346143465, 997.971380355398,
1004.4672957051, 1002.54036572775, 1002.2292388993, 999.116379988893,
997.364309124077, 997.937032776913, 1001.14544537612, 1002.08056674659,
1000.0422658299, 1013.29862597967, 1005.06669915366, 1003.93467692475,
1000.02290694207, 1004.31923128858, 1000.2377260519, 1001.8997238369,
1003.23718800791, 1000.3181007915, 991.917076181167, 994.268259914595,
984.200151469856, 1001.75469999858, 1000.67737011882, 998.160204449011,
1002.55445787016, 999.619189546307, 1000.62462329497, 1002.6131633385,
1002.68202480584, 1001.76690658846, 1000.1486358877, 999.041146242958,
996.826940359061, 992.174732415707, 993.414424263201, 995.607929239509,
1002.3675247675, 1000.59471576055, 999.702054315567, 995.463461260932,
1000.19683225081, 997.291471462544, 1000.49899512487, 1000.16517157422,
1000.26949897499, 1000.90194838628, 997.540443383467, 1001.63525170543,
1000.15589773267, 1001.84917352127, 999.143272890465, 998.838174280258,
1001.07658425743, 997.785664145926, 1004.3385479368, 1004.40588599635,
1000.12771042363, 993.730433866373, 998.823414049946, 992.741136330753,
999.111706290616, 997.858229406642, 997.578584047386, 997.041879724825,
994.87259980467, 994.676525112309, 995.587091814466, 998.785952807378,
995.763507296891), I = c(994.035709684742, 994.890815628412,
997.18267770374, 998.564426335124, 996.851278420874, 1000.16039368502,
1003.52155765272, 1002.1043798945, 1002.7069399281, 1005.49897156208,
1005.81171180245, 998.62698748611, 999.56563615154, 1002.87987510596,
998.728473297166, 1017.2093269366, 1007.79412746756, 1008.11964589961,
1004.9525336386, 1009.50695673265, 1004.15235381401, 1006.12944883686,
1008.01447499455, 1000.78341401868, 998.758028059129, 999.512821404105,
990.209681874658, 1004.22150266269, 1004.2013984755, 1000.20800539735,
1004.19096721582, 1000.81528330285, 1001.48137456348, 1002.0809544,
1004.35199943309, 1002.84860039832, 1003.05879540678, 1002.11976068962,
999.730997287674, 997.228449343895, 997.40997781305, 1000.17928456999,
1002.24515223348, 1001.88805943989, 999.907971391359, 997.990314049709,
1002.594272601, 998.723779888022, 1000.58839907176, 998.560175268731,
1001.96978732491, 999.661325019717, 998.135153010693, 999.984520817739,
1002.55036185373, 1004.4252040573, 999.400843752972, 1001.6009125159,
1004.73673205744, 999.807509276376, 1004.84522882347, 1005.71745745982,
1001.02554478707, 995.404874329182, 1001.17048429098, 992.572297236651,
1003.15655538249, 999.360169227143, 999.654883358304, 999.960896943128,
997.384140934815, 997.283148054673, 998.265161196589, 1001.00287124848,
997.515534614852), J = c(1008.23981597718, 1009.51261484649,
1009.42367409926, 1005.06332653216, 1005.02619159395, 1009.07903916629,
1007.56089165218, 1005.49719893791, 1004.91476855238, 1013.03209535721,
1010.84145164945, 1005.86927622259, 1003.25309970443, 1004.68478802971,
1002.71096740085, 1025.56743956652, 1016.32418136177, 1013.09901927997,
1011.92002817369, 1014.69013052771, 1009.67397418906, 1010.29743022209,
1012.07680708286, 1005.94015305892, 1012.48175793277, 1012.41952646586,
1001.00612108991, 1009.63063375751, 1010.56312371765, 1003.08031473771,
1003.35694102903, 1004.28046277054, 999.866407799831, 1006.91036586892,
1007.64737651417, 1006.75669517393, 1008.53691852797, 1007.08645126073,
1004.47409706618, 1004.39617687043, 1003.27924738048, 1006.06169418873,
1005.34939694712, 1005.58288092655, 1004.85729686493, 1007.38032829588,
1011.72595267599, 1004.95764559864, 1006.2406657999, 1003.49843659402,
1004.07498375648, 1003.55732294589, 1001.33918111569, 1000.95678296744,
1002.3200249671, 1003.15289777247, 999.167788093111, 1006.39254974438,
1007.05337876271, 1002.97245026798, 1006.23573445581, 1007.60523861932,
1002.98791225156, 1003.10850022259, 1008.12060882554, 999.995403485561,
1013.58992171981, 1009.93070913311, 1008.10285456645, 1005.04464304009,
1002.02262615479, 1001.05106189387, 1005.62233873107, 1010.11935930848,
1005.87476640145), K = c(994.327042030287, 995.608170991922,
997.033470393412, 1000.15918365269, 998.216388150646, 1001.97377908784,
1003.17401220482, 1001.60211665164, 1002.27932356239, 1002.41479226363,
999.832076213262, 1001.37236796086, 1001.17012593697, 1001.40362599894,
999.964771265342, 1012.75282463779, 1008.65746780516, 1005.290878105,
999.464067607865, 1005.14963479715, 999.649764748948, 1003.33072474503,
1005.69883686071, 1000.36835347925, 993.839707725624, 995.36726126399,
988.307000532414, 1003.03797140798, 1001.98356248343, 999.894390486631,
1004.42881386089, 1002.52938643378, 1000.79036688202, 1002.81796777502,
1004.44686315697, 1000.48131252765, 1002.07031118448, 1001.88437037401,
998.301279282178, 992.327926936543, 992.528325989138, 996.295346692933,
1002.76956021356, 1000.17011585976, 999.88233615018, 999.681970401198,
1002.59521869899, 1000.49579177747, 1004.23210597331, 1007.04880390672,
1004.24930021206, 1001.85997966737, 998.313461257726, 1004.49876374949,
1000.9722244689, 1000.28328142721, 998.117834474685, 1001.93604180609,
1004.36911508867, 1000.39619941862, 1002.11916794344, 1002.78021097217,
999.202219489554, 994.602579098966, 996.747503975562, 992.098413491644,
1000.03472445261, 999.187033093333, 1000.71379455593, 995.66066961146,
996.024445680514, 995.008386022583, 997.917574584763, 999.229331486915,
997.093225761927), L = c(999.225538268699, 999.349990537239,
1001.14010250645, 1001.51403741206, 1000.25571835554, 1003.76051565494,
1002.74763442988, 1001.09116707486, 1003.29833843754, 1006.55857216695,
1007.06029312947, 1000.60539548502, 999.637387760292, 1002.72729847885,
998.034039799405, 1016.5065564384, 1009.68783611392, 1009.47863905986,
1003.56318544047, 1009.23934223585, 1002.81836003896, 1006.49648576605,
1008.95767573724, 1000.05837737854, 1000.40719170043, 999.644079501528,
993.304682798038, 1005.19870793783, 1004.46546567977, 1001.95912937006,
1005.56965921078, 1003.02810334276, 1001.73555945138, 1002.27122847213,
1005.67690071529, 1001.08565421371, 1004.34660284151, 1004.36701185857,
1001.13778488337, 996.248419196021, 996.291832791975, 1001.11347399164,
1002.71639671749, 1002.04095164098, 999.987444674806, 1001.81478467865,
1005.51311465032, 1001.84877511449, 1003.72063461782, 1005.69841082672,
1006.11884162455, 1000.14922997608, 998.788899712536, 1002.26488777145,
1002.47692422786, 1003.03620977913, 997.633160438494, 1003.71871325602,
1006.88800630791, 1002.16160561309, 1001.8572443969, 1003.89090518079,
999.93867109169, 994.892505165028, 998.081210763667, 990.49221922292,
1001.97916368443, 1000.05747905747, 1002.05005047141, 998.237282789462,
998.094784527214, 997.057707013846, 999.919680379218, 1001.67927888372,
998.691024619626), M = c(1009.99385579756, 1011.12126521731,
1010.6989716872, 1003.7899021821, 1004.59413830322, 1008.52123662618,
1006.34418311104, 1004.1077131243, 1004.94124365003, 1011.89121961563,
1010.13326381032, 1005.33467168056, 1001.04545904874, 1002.86650202467,
1000.45601490752, 1022.13789464831, 1016.25544969107, 1012.37379951646,
1008.53744587416, 1012.00856171947, 1006.44029646493, 1007.92145847204,
1011.06711242009, 1003.67962142328, 1013.2326207796, 1010.68633713312,
1001.19234165952, 1008.65720626559, 1009.10677414828, 1003.56217081729,
1003.6553384404, 1004.92332669674, 999.044137362938, 1005.1228056994,
1007.96701055541, 1004.20070031589, 1007.7451172837, 1006.81338213344,
1003.53005530276, 1002.00057785518, 1000.30733607564, 1006.27767029539,
1005.46564282737, 1005.31077105909, 1004.21138025612, 1007.33605094724,
1010.90426287755, 1004.92138251507, 1006.79108056397, 1007.22349662969,
1004.88215501513, 1003.23055080249, 1001.6706218772, 1002.2471948666,
1001.16267428815, 1001.669317131, 997.362509964893, 1007.26747194149,
1007.40312084436, 1003.85188130527, 1003.51813473707, 1004.96827359204,
1001.3586497828, 1002.44180972822, 1003.52588208615, 999.090746091081,
1008.8316595985, 1007.35889570568, 1006.3336610853, 1002.60112153748,
1001.24372245315, 999.614422623217, 1005.16871756657, 1008.83562199571,
1005.14162645295), N = c(999.801263745036, 996.838989582336,
1000.89599227983, 1003.11042068113, 1002.27800090558, 1003.83846437952,
1000.70169995102, 1001.75290674649, 998.660833714301, 1006.69246804854,
1004.7636391085, 1005.63873342951, 1001.37744267414, 1000.97339668679,
1001.98775658049, 1004.70492544978, 1012.11738595707, 1001.0458886613,
996.725751886115, 1003.17906097432, 999.262970466697, 999.451920807283,
1004.61956745266, 1002.8340643117, 997.963377491494, 998.954167698171,
995.898021564517, 1001.74578985593, 1000.33718227001, 1001.00885828308,
1004.7071611424, 1002.91357065339, 1003.41865997847, 1000.11284080893,
1003.65320446801, 1001.68471621974, 998.968038016249, 998.795991193962,
999.638442866221, 996.628274431963, 995.260177765719, 1000.27642468783,
1005.00204428575, 1002.5924005443, 1001.76823718364, 1002.89875624369,
1003.26725194424, 1001.68068636794, 1005.10788499684, 1010.94382735439,
1008.57093653637, 1004.13801289433, 999.908089656425, 1007.14602235806,
1000.95103389689, 996.491714680007, 999.754190491106, 1003.74570635774,
1003.35958383952, 1000.58595620726, 999.0462473717, 1000.1980165471,
998.473722265129, 997.461987403548, 996.129597532203, 996.609969985822,
999.943757410855, 998.068498757686, 1000.14533441949, 993.693995026749,
995.940627650744, 994.614899343371, 1003.42195795554, 1004.06645814493,
1001.56160375018), O = c(1002.96437294923, 997.870867692911,
1002.94619035116, 1003.44844607015, 1003.02403433836, 1004.70457675466,
999.880559826981, 1000.66826545719, 999.59436981446, 1007.32640154038,
1006.7506344557, 1001.59973104217, 1000.71689406196, 1001.15587576193,
999.988638552344, 1006.4489695839, 1010.51785193511, 1003.79329103591,
999.118472788132, 1004.99936090838, 1000.54733638917, 1000.91418088135,
1004.57223746317, 1000.54437978721, 1002.10232992004, 1000.36408792936,
997.9837416027, 1002.92045510619, 1000.58925031439, 1002.47669253217,
1003.86468109537, 1001.3954846972, 1003.99379121188, 997.566194245209,
1003.55543459632, 1001.80643385497, 1001.32843479186, 1000.99816870794,
1002.22142205601, 997.421272961484, 997.52989338229, 1003.56904822059,
1006.29976121969, 1004.17893812675, 1002.05354063484, 1002.80516686935,
1005.94481009989, 1002.24420650476, 1003.87077739797, 1007.51898916194,
1008.04385138833, 999.162247485917, 999.52752418934, 1003.94854087847,
1001.42192692668, 1000.41259599596, 998.733435450058, 1003.70559987919,
1004.95053154685, 1001.54527082822, 997.648675071306, 1001.27825568282,
998.125258605737, 995.38160095025, 997.249111602143, 995.45325930152,
1000.70789460245, 997.60258568041, 1001.06029338143, 995.349858555166,
996.624936012322, 995.67060458657, 1003.99189974754, 1005.66199164861,
1003.38297407426), P = c(1006.28027312932, 1005.24535230967,
1007.68162285336, 1001.08242973466, 1002.99896314, 1005.36085942954,
1001.22060069797, 1000.43007709819, 1000.47666761108, 1008.73650967215,
1007.20593389744, 1004.57722295264, 998.66379615346, 998.711140983915,
999.452420534917, 1008.11715753014, 1013.30601537204, 1002.03237948844,
1002.88799699943, 1005.57921718108, 1000.2243126431, 998.644912829098,
1005.24004334238, 999.475572814555, 1009.53009273459, 1005.96824937368,
1000.35458151391, 1003.75491412513, 1001.62293479253, 1001.13298849399,
1001.30382513004, 1002.21921258547, 999.017064800029, 999.123967212071,
1004.07313151834, 1002.67697914555, 1002.01133614154, 1000.71338636323,
1001.82011380148, 997.859459866021, 997.083115696827, 1003.40649787754,
1006.9700120191, 1004.8346929062, 1004.05060374186, 1003.15582202707,
1006.3003345886, 1001.54086695776, 1004.70486363208, 1007.02302307691,
1004.86622757701, 1000.51968370413, 1003.2273466626, 1002.66173787498,
998.613043102328, 998.987599433243, 997.757375273718, 1006.00477421965,
1004.20438929142, 1001.13798685232, 999.102913452971, 1002.0228708307,
999.410527740961, 999.795880345749, 1001.34241259142, 1001.91885824018,
1003.7550369496, 1002.11369999794, 1002.21121622484, 997.228089565745,
996.717876200798, 997.33958750622, 1004.45145073668, 1008.01351241284,
1008.18987741896)), row.names = c(NA, -75L), class = "data.frame")
I'm not sure whether I should convert the dataset I'm working on into a string for fixing this problem. Is there anyone that can explain and show how to fix it?
The code has been smartly written to work if you pass bare column names.
library(ggstatsplot)
ggbetweenstats(df_join,x = COND, y = P3FCz)
Or column names as strings.
ggbetweenstats(df_join,x = 'COND', y = 'P3FCz')
But it returns an error when you pass column names as variables.
a <- 'COND'
b <- 'P3FCz'
ggbetweenstats(df_join,x = a, y = b)
Error: Can't subset columns that don't exist. x Column
a
doesn't exist.
It would work if you force the evaluation of the variables with !!
.
a <- 'COND'
b <- 'P3FCz'
ggbetweenstats(df_join,x = !!a, y = !!b)
So in your for
loop you may use -
for (i in 5:ncol(df_join)) {
print(ggbetweenstats(df_join, x = 'COND', y = !!colnames(df_join[i])))
}