My coding goals this week were to:
I was successfully able to follow Danielle’s coding steps to adjust the mpg data plot to be more visually appealing as well as conscious of the information being conveyed.
Through aesthetics mapping I was able to change the colour of the graph, and through layering plots I could familiarise myself with the different different R functions code uses (adding a regression line, and marginal distributions of the points etc).
This is the final product:
library(tidyverse)
## ── Attaching packages ────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.2.1 ✓ purrr 0.3.3
## ✓ tibble 2.1.3 ✓ dplyr 0.8.4
## ✓ tidyr 1.0.2 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.4.0
## ── Conflicts ───────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
picture <- ggplot(data = mpg,
mapping = aes(
x = displ,
y = hwy
)) +
geom_point(mapping = aes(colour = factor(cyl))) +
geom_smooth()+
geom_rug()
print(picture)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
Next, I took value from learning to tidy up code to reduce redundant arguments. I soon found myself relying on the labels to identify the inputted variables (this was as a struggle for me), but I eventually got the hang of it!
The dinosaur exercise (5) was a perfect way to practice this skill:
dino <- read_csv("data_dino.csv")
## Parsed with column specification:
## cols(
## horizontal = col_double(),
## vertical = col_double()
## )
picture <- ggplot(dino)+
geom_point(aes(horizontal, vertical))
plot(picture)
Cleaning up the forensic data in exercise 9/10 through utilising a boxplot was the most fun I’ve had in the tutorials so far. I’m not sure what is fueling my aversion to violin plots but I’ll be happy if I never had to see one again. The first graph demonstrates how I have produced two sub-boxplots/facets representing novices and experts. The second graph is a prettier version of the same information!
forensic <- read_csv("data_forensic.csv")
## Parsed with column specification:
## cols(
## participant = col_double(),
## handwriting_expert = col_character(),
## us = col_character(),
## condition = col_character(),
## age = col_double(),
## forensic_scientist = col_character(),
## forensic_specialty = col_character(),
## handwriting_reports = col_double(),
## confidence = col_double(),
## familiarity = col_double(),
## feature = col_character(),
## est = col_double(),
## true = col_double(),
## band = col_character()
## )
picture <- ggplot(data = forensic) +
geom_boxplot(mapping = aes(band, est)) +
facet_wrap(facets = vars(handwriting_expert))
print(picture)
## Warning: Removed 4 rows containing non-finite values (stat_boxplot).
picture <- ggplot(data = forensic) +
geom_boxplot(mapping = aes(band, est, fill = band)) +
facet_wrap(facets = vars(handwriting_expert))+
theme_minimal() +
scale_x_discrete(
name = NULL,
labels = NULL) +
scale_y_continuous(
name = "Estimate") +
ggtitle(
label = "Estimated frequency of handwriting features") +
scale_fill_viridis_d(
alpha = .5,
name = NULL)
print(picture)
## Warning: Removed 4 rows containing non-finite values (stat_boxplot).
We had to absorb lots of information this week. I think it is important for me to complete the refresher tutorial suggested by Danielle. As I work through the future weeks of coding I would also like to read Danielle’s advanced workshop and hopefully learn to finesse the s*** out of R. All in good time :D