Hi PSYC3361, welcome to my week 2 learning log!
1. Goals:
- to complete another coding session (data visualisation with ggplot2)
- to become more comfortable using the R Studio Cloud platform
- to develop a greater understanding of how coding and R can help in research
2. How did I go at achieving my goals? (Challenges/Successes)
- I found the second coding session far more difficult, and there was a lot of rewind, pause etc.
- I struggle with understanding and creating plots in computer packages that I’m familiar with, so my mind was exploding this week!
- Luckily Danielle started basic and took us through step by step.
- My biggest challenge this week, was that i did the session in bits, so coming back to data from a few days ago started causing lots of error messages. I decided to redo everything I’d done which wasn’t much - my issue was that I hadn’t reloaded the library that I wanted to retrieve my data from.
- I learned that aesthetics apply to coding and aren’t just nice cushions and paint colours! Turns out in coding, they’re the way variables are mapped onto visual properties of geoms!
- First I drew a basic scatterplot:

- Then we added colour, changed the size etc.
- Unfortunately at this point, I can’t find any of my work. Although I kept saving after each plot I ran, this has apparently saved (or not…I’ll never know) into the blackhole that is R. I have now learned that in fact you can save what was a temporary copy that I was writing in, to a permanent copy for the remainder of the sessions. I will go onto explain what I did, nevertheless:
- I then added a regression line, and a rug plot using geom_smooth and geom_rug. These are called layers.
- As we learned in Friday’s workshop, just because code and data is supplied, doesn’t mean it’s replicable. Tidy code can help with this!
- The code was made ‘tidier’ using global aesthetics - which means putting the x and y values in the ggplot parentheses before you write any geoms, as the geoms will use the x and y values they ‘inherit’.
- To tidy further, all white space was deleted, and arguments like x=, y=, mapping=, and data= were deleted as R knows these and so they’re redundant. This is a named argument (ggplot(data=dino)) vs. an unamed argument (ggplot(dino)).
- In exercise 6-8, we had to come up with the names ourselves to replace the emojis Danielle’s daughter had rudely inserted into our beautiful code!
- In exercise 9 and 10, we plotted forensic handwriting data using boxplots (geom_boxplot) and a violin plot (geom_violin).
- From here, we split expert data and novice data into two separate plots using (facet_wrap(vars(handwriting_expert))).
- I got quite confused with these different plots as I didn’t understand the data…
- Finally, we made the plots pretty! Isn’t that what aesthetics should have been doing all along :D – We filled the bands (fill=band) – We removed the gray background (pic + theme_minimal) – We removed the cluttered x-axis label (pic + theme_minimal() + scale_x_discrete(name = NULL, labels = NULL)) – We also removed the y-axis label as the data spoke for itself (pic + theme_minimal() + scale_x_discrete(name = NULL, labels = NULL) + scale_y_continuous(name = NULL)) – We gave the plot a title (pic <- pic + ggtitle(Estimated frequency of handwriting features)) – We changed the colours of the bands (pic + scale_fill_viridis_d()) – We changed the transparency of the colour of the bands so we could see the mean line (pic + scale_fill_viridis_d(alpha = .5)) – Finally, we removed the name of the band key (pic+scale_fill_viridis_d(alpha = .5, name = NULL)) VOILA!!! I apologise again, this would have made much more sense if I could find photos of my pretty little plots, but alas…that is learning!
Next Steps:
- Onwards and upwards!…
- Next week (Week 3), my plan is to get through the final of Danielle’s coding sessions (Data Wrangling) so that I have enough knowledge to begin on our COVID articles in the week 3 workshop.
- My other goal is, to not lose all my code!
