Home > Software engineering >  Adding multiple verticle lines to a ggplot2 boxplot
Adding multiple verticle lines to a ggplot2 boxplot

Time:05-02

I have the following code:

ggplot(IDRAnew,aes(x=IDRAnew$Condition,y=IDRAnew$Score,color=Group))   
  geom_boxplot(outlier.alpha = 0)   
  geom_vline(aes(xintercept = c(1.5)),linetype = "dotted")   
  facet_wrap(~Reward, scales='free')    
  theme_classic()   
  theme(strip.text = element_text(size=17,face="bold"),
    panel.spacing = unit(2, "lines"),
    plot.title = element_text(face="bold",hjust=0.5,vjust=2,size=17), 
    axis.title = element_text(face="bold"),  
    axis.title.x = element_text(vjust=-1.5,size=17), 
    axis.title.y = element_text(vjust=2.5,size=17),
    axis.text.x = element_text(size=17,face="bold"),
    axis.text.y = element_text(size=17,face="bold"),
    legend.text = element_text(size=17),
    legend.title = element_text(size=17,face="bold"))   
  ggtitle("Reaction Accuracy")   
  xlab("Condition")   
  ylab("Reaction Accuracy")

This gives me the following output:

enter image description here

I want to add another vertical line between SH and Social on each of the plots below.

I tried to search for different ways to do this but was unsuccessful!

Would anybody be able to give me a helping hand?

Minimal Reproducible example of IDRTnew dataset:

structure(list(ID = c("1993", "1993", "1993", "1993", "1993", 
"1993", "1997", "1997", "1997", "1997", "1997", "1997", "19998", 
"19998", "19998", "19998", "19998", "19998", "3122", "3122", 
"3122", "3122", "3122", "3122", "3152", "3152", "3152", "3152", 
"3152", "3152", "330", "330", "330", "330", "330", "330", "354", 
"354", "354", "354", "354", "354", "363", "363", "363", "363", 
"363", "363", "369", "369", "369", "369", "369", "369", "370", 
"370", "370", "370", "370", "370", "375", "375", "375", "375", 
"375", "375", "377", "377", "377", "377", "377", "377", "378", 
"378", "378", "378", "378", "378", "379", "379", "379", "379", 
"379", "379", "380", "380", "380", "380", "380", "380", "381", 
"381", "381", "381", "381", "381", "3862", "3862", "3862", "3862", 
"3862", "3862", "3872", "3872", "3872", "3872", "3872", "3872", 
"388", "388", "388", "388", "388", "388", "390", "390", "390", 
"390", "390", "390", "392", "392", "392", "392", "392", "392", 
"393", "393", "393", "393", "393", "393", "394", "394", "394", 
"394", "394", "394", "395", "395", "395", "395", "395", "395", 
"399", "399", "399", "399", "399", "399", "5512", "5512", "5512", 
"5512", "5512", "5512", "382", "382", "382", "382", "382", "382", 
"1001", "1001", "1001", "1001", "1001", "1001", "1002", "1002", 
"1002", "1002", "1002", "1002", "1003", "1003", "1003", "1003", 
"1003", "1003", "1004", "1004", "1004", "1004", "1004", "1004", 
"1005", "1005", "1005", "1005", "1005", "1005", "1006", "1006", 
"1006", "1006", "1006", "1006", "1007", "1007", "1007", "1007", 
"1007", "1007", "1008", "1008", "1008", "1008", "1008", "1008", 
"1009", "1009", "1009", "1009", "1009", "1009", "1012", "1012", 
"1012", "1012", "1012", "1012", "1013", "1013", "1013", "1013", 
"1013", "1013", "1014", "1014", "1014", "1014", "1014", "1014", 
"1015", "1015", "1015", "1015", "1015", "1015", "1016", "1016", 
"1016", "1016", "1016", "1016", "1017", "1017", "1017", "1017", 
"1017", "1017", "1020", "1020", "1020", "1020", "1020", "1020", 
"1021", "1021", "1021", "1021", "1021", "1021", "1024", "1024", 
"1024", "1024", "1024", "1024", "1025", "1025", "1025", "1025", 
"1025", "1025", "1026", "1026", "1026", "1026", "1026", "1026", 
"1027", "1027", "1027", "1027", "1027", "1027", "1192", "1192", 
"1192", "1192", "1192", "1192", "1422", "1422", "1422", "1422", 
"1422", "1422", "1492", "1492", "1492", "1492", "1492", "1492", 
"1592", "1592", "1592", "1592", "1592", "1592", "1602", "1602", 
"1602", "1602", "1602", "1602", "1642", "1642", "1642", "1642", 
"1642", "1642", "171", "171", "171", "171", "171", "171", "1722", 
"1722", "1722", "1722", "1722", "1722", "1732", "1732", "1732", 
"1732", "1732", "1732", "174", "174", "174", "174", "174", "174", 
"175", "175", "175", "175", "175", "175", "1752", "1752", "1752", 
"1752", "1752", "1752", "1762", "1762", "1762", "1762", "1762", 
"1762", "1782", "1782", "1782", "1782", "1782", "1782", "1802", 
"1802", "1802", "1802", "1802", "1802", "182", "182", "182", 
"182", "182", "182", "184", "184", "184", "184", "184", "184", 
"1852", "1852", "1852", "1852", "1852", "1852", "186", "186", 
"186", "186", "186", "186", "187", "187", "187", "187", "187", 
"187", "188", "188", "188", "188", "188", "188", "1892", "1892", 
"1892", "1892", "1892", "1892", "190", "190", "190", "190", "190", 
"190", "192", "192", "192", "192", "192", "192", "1924", "1924", 
"1924", "1924", "1924", "1924", "193", "193", "193", "193", "193", 
"193", "195", "195", "195", "195", "195", "195", "196", "196", 
"196", "196", "196", "196", "197", "197", "197", "197", "197", 
"197", "1992", "1992", "1992", "1992", "1992", "1992", "19922", 
"19922", "19922", "19922", "19922", "19922", "1999", "1999", 
"1999", "1999", "1999", "1999", "19992", "19992", "19992", "19992", 
"19992", "19992", "199945", "199945", "199945", "199945", "199945", 
"199945", "199949", "199949", "199949", "199949", "199949", "199949", 
"199951", "199951", "199951", "199951", "199951", "199951", "199952", 
"199952", "199952", "199952", "199952", "199952", "19922", "19922", 
"19922", "19922", "19922", "19922", "490", "490", "490", "490", 
"490", "490", "181", "181", "181", "181", "181", "181", "3812", 
"3812", "3812", "3812", "3812", "3812", "199950", "199950", "199950", 
"199950", "199950", "199950", "191", "191", "191", "191", "191", 
"191"), Condition = structure(c(2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 
1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 
2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 
2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 
1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 
2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 
2L, 1L, 2L, 3L,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
1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 
2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 
2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 
1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 
2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 
2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 
1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 
2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 
2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 
1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 
2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 
2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 
1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L), .Label = c("Money", 
"SH", "Social"), class = "factor"), Score = c(0.221611076, 0.206888887611111, 
0.2319999696, 0.228521740956522, 0.206187486625, 0.220866648533333, 
0.227608773956522, 0.241291721625, 0.24412006376, 0.238473741684211, 
0.2352000951, 0.233545574272727, 0.260041663875, 0.265705879882353, 
0.254225776967742, 0.250256428333333, 0.256172385758621, 0.258117654705882, 
0.218822224977778, 0.219707332097561, 0.216555555666667, 0.2150000135625, 
0.218574478382979, 0.216552615184211, 0.237181836863636, 0.243347841782609, 
0.236708313208333, 0.239999993733333, 0.240576936653846, 0.243055529055556, 
0.226071425785714, 0.234166675111111, 0.247500022333333, 0.26374999275, 
0.249636368363636, 0.192642842, 0.2230799676, 0.233000015052632, 
0.246157909736842, 0.232739137565217, 0.223999977217391, 0.213499954928571, 
0.2318399144, 0.222888787722222, 0.232055505166667, 0.224799911233333, 
0.211857069142857, 0.205277721277778, 0.266269417846154, 0.268956713043478, 
0.260214464857143, 0.265853131441176, 0.253393011392857, 0.253192479884615, 
0.273046510116279, 0.261442312788462, 0.265268302536585, 0.259176473921569, 
0.268714257714286, 0.258478247673913, 0.243666579416667, 0.244777692722222, 
0.240954475, 0.252370286925926, 0.23419988644, 0.213499903772727, 
0.245809521095238, 0.27050002815, 0.269909089227273, 0.27260001885, 
0.251499951, 0.270038503769231, 0.252324259, 0.250676414588235, 
0.2493436709375, 0.255290277612903, 0.234612849451613, 0.247166601833333, 
0.24452014446, 0.255224665836735, 0.252487335333333, 0.256893751531915, 
0.2488251865, 0.240069927116279, 0.238666693296296, 0.222346159230769, 
0.243000002529412, 0.251777801361111, 0.234608712434783, 0.237823472470588, 
0.286471776226415, 0.281888988259259, 0.277262029119048, 0.278018955849057, 
0.293561074756098, 0.27339032797561, 0.247333394222222, 0.223111073111111, 
0.271263147578947, 0.270000009, 0.306285688, 0.2608749865, 0.248806445870968, 
0.251823551470588, 0.262323526705882, 0.245073149829268, 0.248054040351351, 
0.260212125121212, 0.288428570464286, 0.284000015233333, 0.277037046592593, 
0.265325003825, 0.26918749503125, 0.27525001759375, 0.245652157304348, 
0.208157878157895, 0.222666676866667, 0.219999988888889, 0.237923081230769, 
0.228375017625, 0.239026289368421, 0.232055571472222, 0.23143748946875, 
0.237034485310345, 0.244894736736842, 0.237342861828571, 0.298294067323529, 
0.3083666086, 0.314666603606061, 0.304142781678571, 0.295823461764706, 
0.2948749436875, 0.22432435527027, 0.220128212307692, 0.224151546363636, 
0.222783778243243, 0.234615371846154, 0.229194442555556, 0.25588891237037, 
0.24439997675, 0.273625056, 0.237055593, 0.242615397115385, 0.23515001535, 
0.309627882232558, 0.283799960844444, 0.287379240275862, 0.27809298872093, 
0.307733265533333, 0.284405353864865, 0.247389064888889, 0.234428729214286, 
0.237423245692308, 0.245666821888889, 0.23965643346875, 0.230842326736842, 
0.259000150956522, 0.270062684979167, 0.267195810347826, 0.279690657261905, 
0.259089061977778, 0.259390418121951, 0.231464232785714, 0.223166604916667, 
0.253857056333333, 0.240857073285714, 0.229923009769231, 0.232588179058824, 
0.301863561954545, 0.302518455962963, 0.308526252421053, 0.30427990916, 
0.302178476571429, 0.297428488785714, 0.256406247625, 0.245357138785714, 
0.257555564185185, 0.249743583871795, 0.245482748965517, 0.253935460193548, 
0.260249932555556, 0.268871729128205, 0.266333262027778, 0.277163184306122, 
0.2587221595, 0.26697293472973, 0.287999913714286, 0.2829999625625, 
0.266212051515152, 0.260794792384615, 0.274999943606061, 0.269137859275862, 
0.220071341392857, 0.246714183333333, 0.245272647227273, 0.223444355888889, 
0.222380865190476, 0.241058812411765, 0.255857161, 0.248709678612903, 
0.254428568190476, 0.237916658333333, 0.249833313633333, 0.251535730678571, 
0.249222172583333, 0.261057077057143, 0.25704994195, 0.250085653542857, 
0.254029372088235, 0.246263108763158, 0.26118749375, 0.2679499745, 
0.265999994842105, 0.27279996855, 0.269000016615385, 0.27300002452381, 
0.232444392333333, 0.214545390909091, 0.217888841037037, 0.236333234, 
0.227263074263158, 0.209999912789474, 0.243666518969697, 0.245648480837838, 
0.243172234586207, 0.233742720771429, 0.247083207027778, 0.2347811238125, 
0.2584999321, 0.24666661025, 0.247388866111111, 0.264333267916667, 
0.258636257818182, 0.251521670304348, 0.252999991083333, 0.274694455916667, 
0.264291683791667, 0.255249959892857, 0.26599996521875, 0.268000012333333, 
0.28760011676, 0.28362509603125, 0.276000023, 0.303142956428571, 
0.2926000594, 0.27332008352, 0.230035637178571, 0.243259191555556, 
0.257083237125, 0.250909079181818, 0.247454437318182, 0.244222111277778, 
0.267852937411765, 0.271642860880952, 0.25706251709375, 0.259883747581395, 
0.2626000046, 0.269333318444444, 0.2913333892, 0.274055494055556, 
0.288782617391304, 0.281500016, 0.2886250316875, 0.278814827888889, 
0.241263132394737, 0.231783789567568, 0.21995653273913, 0.220709670096774, 
0.232263138473684, 0.227925909925926, 0.274657072342857, 0.280783730513514, 
0.276036977777778, 0.274487128512821, 0.261605193710526, 0.274090781363636, 
0.256043527347826, 0.270230797538462, 0.279818253, 0.27348006248, 
0.256368486421053, 0.264411785941176, 0.256823441588235, 0.245217313, 
0.24125917762963, 0.232291619083333, 0.2524999115, 0.241516067258065, 
0.247185150703704, 0.253605986939394, 0.257722139388889, 0.252272660090909, 
0.256947304, 0.257227204045455, 0.275510493680851, 0.285863480681818, 
0.262190324952381, 0.280282879773585, 0.27520392377551, 0.2588220756, 
0.261139514883721, 0.255875021145833, 0.244977808, 0.259976753, 
0.258000018632653, 0.234500005190476, 0.2604999690625, 0.2324499964, 
0.264541685541667, 0.249575737727273, 0.203000017642857, 0.244416693791667, 
0.243964263321429, 0.249766643933333, 0.198888911333333, 0.24651353427027, 
0.242615406384615, 0.233827590931034, 0.23454538269697, 0.253538370153846, 
0.248366594433333, 0.252882284323529, 0.252646979205882, 0.250792996724138, 
0.221374889333333, 0.211666601703704, 0.201422994038462, 0.209307624884615, 
0.2226999164, 0.213142769761905, 0.235451544580645, 0.237605983636364, 
0.233903146677419, 0.230499936555556, 0.23995990764, 0.235515074393939, 
0.240000009545455, 0.232523793380952, 0.238259262555556, 0.2357916535, 
0.232558818529412, 0.235111104185185, 0.25529157125, 0.250041633833333, 
0.273208250541667, 0.263499948722222, 0.246291597708333, 0.244470484176471, 
0.22815640271875, 0.22255568375, 0.220964414785714, 0.224722385388889, 
0.219869738173913, 0.2112309475, 0.237142750285714, 0.245333258366667, 
0.236210459210526, 0.24922213737037, 0.224666595428571, 0.243526220473684, 
0.267869565782609, 0.282962966777778, 0.273772694727273, 0.284399994133333, 
0.25551998136, 0.2689000289, 0.256117659470588, 0.271444453037037, 
0.2560625075625, 0.252645177193548, 0.26251999848, 0.240714322857143, 
0.2512999057, 0.29583992956, 0.281925872407407, 0.287605979181818, 
0.260388785, 0.296782535043478, 0.237711101155556, 0.249524992675, 
0.2431428774, 0.247282577717391, 0.231755574666667, 0.236341464829268, 
0.242799981433333, 0.241800028885714, 0.24684000968, 0.238315783131579, 
0.241729742756757, 0.210185174481481, 0.225588293647059, 0.222823633882353, 
0.2278125881875, 0.21890008455, 0.226178629, 0.219526441421053, 
0.211249977375, 0.217173897913043, 0.2240999938, 0.223684198, 
0.211866680866667, 0.212857121619048, 0.243545618878788, 0.258933472633333, 
0.2302001833, 0.251739304826087, 0.24411129062963, 0.23662084537931, 
0.195000145, 0.213087154478261, 0.186750114, 0.20812016488, 0.231142997714286, 
0.21812013628, 0.252904755761905, 0.241294103411765, 0.24183999076, 
0.240500022916667, 0.254666725666667, 0.247681823681818, 0.225026962054054, 
0.210073992074074, 0.224115325961538, 0.222111026527778, 0.217529331970588, 
0.218382267529412, 0.241200140457143, 0.237963155333333, 0.245565362434783, 
0.245676636735294, 0.23380016328, 0.234291831625, 0.259823546764706, 
0.2422999461, 0.251066668933333, 0.22864999775, 0.262578926526316, 
0.233666698111111, 0.26059517397619, 0.24753120528125, 0.252969611787879, 
0.266944355416667, 0.251853599804878, 0.257299917925, 0.240636370454545, 
0.250892877571429, 0.269588218, 0.240586206793103, 0.232749988583333, 
0.250000008888889, 0.258468075, 0.251829781361702, 0.257641009794872, 
0.249021266404255, 0.254190473309524, 0.241840915295455, 0.282767379023256, 
0.275352863647059, 0.274970496323529, 0.288102498358974, 0.274428497, 
0.259230674769231, 0.254157882, 0.2496999265, 0.2209999565, 0.25166670475, 
0.26030000445, 0.242944452611111, 0.306541830291667, 0.277034636172414, 
0.27975015334375, 0.281909249090909, 0.31016016016, 0.279727430060606, 
0.231699951633333, 0.226371377, 0.235916574833333, 0.228586147758621, 
0.230285636214286, 0.240481412037037, 0.242555611666667, 0.25845010875, 
0.231857257142857, 0.249205210333333, 0.247047696761905, 0.232548459967742, 
0.282382425088235, 0.264577012615385, 0.278575868333333, 0.2825625985, 
0.27254177125, 0.275424350333333, 0.256368611868421, 0.261394081606061, 
0.259485006242424, 0.268589887692308, 0.241216395324324, 0.25932275083871, 
0.240428498821429, 0.238733259866667, 0.23574991225, 0.244956472608696, 
0.248870880516129, 0.2653124034375, 0.248142810047619, 0.264461517307692, 
0.261307716153846, 0.238578984631579, 0.277941198882353, 0.229461559923077, 
0.27259369190625, 0.273410173461538, 0.26809083330303, 0.284166589375, 
0.282264646352941, 0.265302954272727, 0.258647063117647, 0.2565000355, 
0.254529392058824, 0.232392856107143, 0.22980002155, 0.245047626047619, 
0.279326019043478, 0.263157850868421, 0.286130366043478, 0.275814745185185, 
0.281524956225, 0.265363541636364, 0.229149919825, 0.2269999161875, 
0.214912963956522, 0.22574996955, 0.213696906212121, 0.221666583407407, 
0.295230801230769, 0.294124990708333, 0.2932499945, 0.270708332333333, 
0.271035696714286, 0.279705889, 0.276954639909091, 0.285567663756757, 
0.278821510928571, 0.288344901206897, 0.21375000475, 0.270428637085714
), Group = structure(c(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, 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, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1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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, 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, 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("HC", "SH"), class = "factor"), 
    Reward = c("Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward", "Neutral", "Neutral", "Neutral", "Reward", "Reward", 
    "Reward")), row.names = c(NA, -546L), class = c("tbl_df", 
"tbl", "data.frame"))

CodePudding user response:

Take the xintercept outside of aes then you can pass multiple values to it. That way, you fon't need a second geom_vline call. You can also simplify your code a bit by avoiding the IDRAnew$variable syntax inside aes, and using inheritance in the theme elements.

ggplot(IDRAnew, aes(Condition, Score, color = Group))   
  geom_boxplot(outlier.alpha = 0)   
  geom_vline(xintercept = c(1.5, 2.5), linetype = "dotted")   
  facet_wrap(~Reward, scales = "free")    
  theme_classic(base_size = 17)   
  theme(text = element_text(face = "bold"),
    panel.spacing = unit(2, "lines"),
    plot.title = element_text(hjust = 0.5, vjust = 2), 
    axis.title.x = element_text(vjust = -1.5), 
    axis.title.y = element_text(vjust = 2.5))   
  labs(title = "Reaction Accuracy", x = "Condition", y = "Reaction Accuracy")

enter image description here

CodePudding user response:

You can just add another geom_vline using the following code:

ggplot(IDRAnew,aes(x=IDRAnew$Condition,y=IDRAnew$Score,color=Group))   
  geom_boxplot(outlier.alpha = 0)   
  geom_vline(aes(xintercept = c(1.5)),linetype = "dotted")   
  geom_vline(aes(xintercept = c(2.5)),linetype = "dotted")   
  facet_wrap(~Reward, scales='free')    
  theme_classic()   
  theme(strip.text = element_text(size=17,face="bold"),
        panel.spacing = unit(2, "lines"),
        plot.title = element_text(face="bold",hjust=0.5,vjust=2,size=17), 
        axis.title = element_text(face="bold"),  
        axis.title.x = element_text(vjust=-1.5,size=17), 
        axis.title.y = element_text(vjust=2.5,size=17),
        axis.text.x = element_text(size=17,face="bold"),
        axis.text.y = element_text(size=17,face="bold"),
        legend.text = element_text(size=17),
        legend.title = element_text(size=17,face="bold"))   
  ggtitle("Reaction Accuracy")   
  xlab("Condition")   
  ylab("Reaction Accuracy")

Output:

enter image description here

  • Related