A Piece of Code I’m Proud Of

This piece of code is what my team and I achieved when reproducing one of the graphs for paper 2. It took a 4 hour zoom call to reach the final result and I have to admit, I left that zoom call half way through (around 10pm) because I felt brain dead from looking at the code for so long trying to figure out the next steps. Nonetheless, I’m so proud of my team and I, thus, a big shout-out to my team members!

Study3 <- Study3 %>% 
  rowwise() %>% 
  mutate(PD = sum(RECODE1, RECODE2, RECODE3, RECODE4, RECODE5))
Study3 <- Study3 %>% rowwise() %>% mutate(AvgPD = PD/5)

ggplot(data= Study3, mapping = 
         aes(x= bed, y= AvgPD, group=bed)) + 
  geom_violin()

Study3$bed <- factor(Study3$bed, levels = c('0','2', '1')) 

install.packages("ggeasy") 
library(ggeasy)

ggplot(data= Study3, mapping = 
         aes(x= bed, y= AvgPD, group=bed, fill=bed)) + 
  geom_violin()+ 
  scale_x_discrete(name= NULL, breaks = 
                                    c('0','2','1'), 
                   labels = c('Control', 'Information Only', 
                              'Information + Empathy')) + 
  scale_y_continuous(name = 'Physical-Distancing Motivation') + 
  theme(panel.background = element_blank(), axis.line = 
          element_line(),panel.border = 
          element_rect(fill = NA, size = 0.5))  + 
  scale_fill_manual(values = 
                      c('lightskyblue2','deepskyblue4',
                        'darkolivegreen2')) + 
  easy_remove_legend() + 
  geom_boxplot(width=0.1, color="black", fill = 'white') + 
  stat_summary(fun= 'mean', geom='point', shape = 9, 
               colour = 'black', cex=3) 

I’m not sure whether we need to explain the piece of code but this was the final result: