
---
title: "M7: Your figures, and the start of your poster"
author: "Your group's names (and SUNet IDs)"
date: "`r Sys.Date()`"
output: pdf_document
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
library(coursekata)
library(here)
```

<!-- Fill in every line marked [...]. The step numbers match the steps on the
handout. Throughout, replace Thumb (the outcome), Sex (the explanatory
variable), and Job (the question 2 variable) with your own variables. One of
you should knit this to PDF (Session -> Restart R, then Knit -> Knit to PDF)
and submit this file and the PDF on Gradescope, adding the other members of
your group. -->

## Step 1. Your folder

- **Who will upload the changed files to the shared folder at the end of section:** [...]

## Step 2. Your processed data

```{r load-data}
# Replace this with:
#   processed <- read.csv(here("data", "processed", "processed-data.csv")) # the data you prepared in prepare-data.R
# (Fingers is only here so the file knits before you start.)
# If the processed data file still needs a change, make the change in
# R/prepare-data.R and run that script again; do not change the data here.
processed <- Fingers
```

## Step 3. The question 1 model

```{r q1-model}
q1_model <- lm(Thumb ~ Sex, data = processed)
q1_model
supernova(q1_model)

# Any whole number works; with the same number, every knit produces the
# same 1,000 shuffled b1s and the same proportion.
set.seed(10)
sample_b1 <- b1(Thumb ~ Sex, data = processed)
shuffled_b1s <- do(1000) * b1(shuffle(Thumb) ~ Sex, data = processed)
mean(abs(shuffled_b1s$b1) >= abs(sample_b1))
```

- **Do `b1` and PRE equal the values in your M6 PDF? If either number differs, the reason for the difference:** [...]

## Step 4. Question 2

```{r question-2}
# If your question 2 variable is in your dataset: b1 for the question 1
# model within each group (copy one line per group, with your group names).
# If it is not, delete this chunk and answer the second prompt below.
# If your question 2 variable is quantitative, use the grouped variable that
# you made in R/prepare-data.R (two or three groups, as in M6).
#   b1(Thumb ~ Sex, data = filter(processed, Job == "a group name"))
favstats(Thumb ~ Sex + Job, data = processed)
```

- **`b1` in each group, and whether `b1` is about the same in every group or differs between groups in its direction or size:** [...]
- **If your question 2 variable is not in your dataset, the variable you described in M5 and the pattern you would expect across its groups:** [...]

## Step 5. Figure 1, for question 1

```{r figure1, fig.cap = "Thumb Length by Sex in the Fingers Data"}
# Replace fig.cap above with your figure's title, in title case.
figure1 <- gf_jitter(Thumb ~ Sex, data = processed, width = 0.1, alpha = 0.5) %>%
  gf_model(q1_model) %>%
  gf_labs(x = "Sex", y = "Thumb length (mm)") %>%
  gf_theme(theme_classic(base_size = 16))
# If your groups are codes (1, 2), name them on the plot by adding a line:
#   %>% gf_refine(scale_x_discrete(labels = c("1" = "Female", "2" = "Male")))
# For a quantitative explanatory variable, start instead with:
#   gf_point(outcome ~ explanatory, data = processed) %>% gf_lm() %>% ...
figure1
dir.create(here("figures"), showWarnings = FALSE)   # in case the folder is missing
ggsave(here("figures", "figure1.png"), figure1, width = 7, height = 5, dpi = 300)
```

- **Take-home sentence (your finding, with a number and its units):** [...]
- **Checklist (step 5 on the handout): plot type, outcome on the y-axis, model drawn, axes labeled in words with units, groups named in words (renamed on the plot if coded), text size:** [every item met / the items still missing]

## Step 6. Figure 2, for question 2

```{r figure2, fig.cap = "Thumb Length by Sex Within Each Job Category"}
# If your question 2 variable is not in your dataset, delete this chunk:
# your group makes Figure 1 only, and your answer to step 4 takes the place
# of Figure 2 on your poster.
# To name coded panels, give gf_facet_grid() a labeller, for example:
#   gf_facet_grid(. ~ Job, labeller = labeller(Job = c("1" = "No job", "2" = "Part-time")))
figure2 <- gf_jitter(Thumb ~ Sex, data = processed, width = 0.1, alpha = 0.5) %>%
  gf_facet_grid(. ~ Job) %>%
  gf_labs(x = "Sex", y = "Thumb length (mm)") %>%
  gf_theme(theme_classic(base_size = 16))
figure2
ggsave(here("figures", "figure2.png"), figure2, width = 9, height = 5, dpi = 300)
```

- **Take-home sentence (your finding, with the `b1`s from step 4 and their units):** [...]
- **Checklist (the same items as for Figure 1; the model is optional in Figure 2):** [every item met / the items still missing]

## Step 7. The TA check

- **Your TA's comments on Figure 1:** [...]
- **Your TA's comments on Figure 2:** [...]
- **Each revision you made in response, with its reason:** [...]

## Step 8. Your poster

- **The name and location of the poster file in your shared folder:** [...]
- **Your poster's title (your main finding for question 1 in words: the direction of the relationship and its strength, with no numbers):** [...]
- **The other parts of the poster filled in so far (both questions, each figure with its take-home sentence):** [...]
