Week 3

Goals

This week I had three goals:

  1. Finish Danielle’s coding modules and exercises on data wrangling
  2. Continue practicing my data visualisation skills by creating a column graph
  3. Successfully chunk code from R to R Markdown and publish this week’s learning log

The Exercises

Shown below is my coding progress for the data wrangling exercises using the swow dataset. This included renaming or creating variables, filtering, arranging and selecting the data.

Loading the packages and reading the data

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.3     ✓ purrr   0.3.4
## ✓ tibble  3.1.2     ✓ dplyr   1.0.6
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
setwd("~/Desktop/dance_1006868")
swow <- read_tsv(file = "data_swow.csv.zip")
## ! Multiple files in zip: reading ''swow.csv''
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   cue = col_character(),
##   response = col_character(),
##   R1 = col_double(),
##   N = col_double(),
##   R1.Strength = col_double()
## )

Data wrangling: renaming, filtering, selecting etc.

swow <- swow %>% rename(n_response = R1, n_total = N, strength = R1.Strength)
swow <- swow %>% mutate(id = 1:n()) #

woman_bck <- swow %>% filter(response == "woman", n_response > 1) %>% arrange(desc(strength)) %>% select(-n_response, -n_total)%>% mutate(rank = rank(-strength), type = "backward", word = "woman", associate = cue)
man_fwd <- swow %>% filter(cue == "man", n_response > 1) %>% arrange(desc(strength)) %>% select(-n_response, -n_total) %>% mutate(rank = rank(-strength), type = "forward", word = "man", associate = response)
man_bck <- swow %>% filter(response == "man", n_response > 1) %>% arrange(desc(strength)) %>% select(-n_response, -n_total)%>% mutate(rank = rank(-strength), type = "backward", word = "man", associate = cue)

gender <- bind_rows(woman_bck, man_fwd, man_bck) %>% select(id:associate) %>% filter(associate != "man", associate != "woman") 

Binding the data

After binding the three created variables of man_bck, man_fwd and woman_bck into gender, I then created gender_bck to analyse backward associations of ‘woman’ and ‘man’.

gender_bck <- gender %>% filter(type == "backward") %>% pivot_wider(id_cols = associate, names_from = word, values_from = rank)
gender_bck <- gender_bck %>% mutate(woman = replace_na(1/woman, 0),man = replace_na(1/man, 0), diff = woman - man) %>% arrange(diff)

Graphing the data

I recalled my knowledge from last week’s modules on data visualisation (with some help from Slack) to create this graph.

ggplot(data = gender_bck, mapping = aes(x = associate %>% reorder(diff), y = diff)) + geom_col() + coord_flip()

This graph was way too messy! I was unsure of how to fix it, so I checked the coding channel in Slack to find that someone else also had this issue! Thankfully, the solution to the issue had been explained and I could create the graph below!

picture_bck <- ggplot(data = gender_bck %>% filter(diff < -0.05 | diff > 0.05),mapping = aes(x = associate %>% reorder(diff),y = diff)) +geom_col() +coord_flip()
plot(picture_bck)

Challenges

  • This week my main struggles revolved around the working directory and creating a graph from the swow data. When initially trying to export the swow data into the environment, I received an error saying the file could not be found in the ‘working directory’ despite already having the file downloaded. Not knowing what this meant, I googled the error and found a manual route to change the working directory so the file could be found in its specific folder. After this, I was able to successfully export the data into the environment and continue with the exercises!
  • The second issue I had was constructing the graph from the final exercise. When constructing the column graph, I noticed it was initially very messy and unhelpful in interpreting the data. I realised that this was because there was over 400 entries of data. I tried at first googling how to restrict data in graphs but then checked Slack to see if anyone else was having the same issue. As I previously stated, other people seemed to have the same issue and the solution was explained.

Successes

  • As I struggled a lot last week with transferring code from R into chunks in R Markdown, this week I made it my goal to understand the function more and successfully transfer the code. As I continued to practice this skill from following the exercises, I was able to do this easier than last week! Also, although this week’s topic was very content heavy, I still felt like I could follow along with the modules and that I have a basic grasp of the functions. This was a success for me as I struggled a lot with last week’s content, meaning I am starting to understand R more!
  • I also successfully downloaded the prettydoc package to use this theme!

Next Steps

  • Now that I have completed watching Danielle’s coding videos, my next steps in coding are to keep practicing my new skills. Specifically, I would like to keep practicing my data wrangling and visualisation skills on a different dataset so that I can become more familiar with exploring different data and all the functions of R and R Markdown.
  • My next steps are to also apply these new skills to the data for my group project’s chosen article, so I can start reproducing its graphs and statistics.

Meme of the Week (getting the correct code is the best feeling!)