```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

R Bootcamp Session 3 - Starter Code
July 16, 2025
Sophie Regan and Nina Schoener
Adapted from Emily Rosenthal & Sierra Semko Krouse 


Today, we will learn about data visualisation! (pause for cheers from the audience). To do this, meet your new best friend GGPLOT2. Let's install this library.

```{r}
install.packages("ggplot2")
library(ggplot2)
```

#### DATA VISUALIZATION DEMO ####

# This website has some helpful info about plotting with ggplot: https://datacarpentry.org/R-ecology-lesson/04-visualization-ggplot2.html  

# ggplot cheat sheet: https://www.maths.usyd.edu.au/u/UG/SM/STAT3022/r/current/Misc/data-visualization-2.1.pdf  

# R-graph gallery: Help choosing and creating types of plots (NOTE: only use the ggplot section on each page) https://www.r-graph-gallery.com/index.html  


We can look at the distribution of heights in our class. A good way to do this is to create a histogram. 
```{r}
# First, we need to manipulate our three height columns into one column. Let's do it this way:
quack_responses_clean <- quack_responses_clean %>%
  mutate(
    height_clean = case_when(
      !is.na(Height4) ~ 48 + as.integer(str_remove(Height4, " in")),
      !is.na(Height5) ~ 60 + as.integer(str_remove(Height5, " in")),
      !is.na(Height6) ~ 72 + as.integer(str_remove(Height6, " in")),
      TRUE ~ NA_integer_
    )
  )

# Now that we have one column, let's create a simple histogram of heights. What do you notice?

```
Cool! We created our first ggplot plot. There are a few things to note. 
First, you have to call ggplot.
Then, you have to tell it what dataframe you want to use.
Then, using aes(), you tell it what columns you want plotted.
Finally, you tell it what kind of plot you want. This time, we used a histogram. 

We can also add other things to our plot. For example, we can change the binwidth on our histogram. 
```{r}


#What changes?
```

Or we can add labels.
```{r}

```

Another thing we can do is change the color or fill of the bars based on another column in our dataset. 
We can use fill = group inside aes() to fill the bars based on that column.

```{r}

```
If we want to see the groups side-by-side instead of stacked, we can change the position to "dodge":

```{r}


```
Instead of a histogram, we can create something similar: a column plot. The difference is that we specify a column for both the x and the y axes. 
```{r}

# First, let's reorder the months
month_levels <- c("January", "February", "March", "April", "May", "June",
                  "July", "August", "September", "October", "November", "December")

quack_responses_clean <- quack_responses_clean %>%
  mutate(MonthBorn = factor(MonthBorn, levels = month_levels, ordered = TRUE))


# Then, we can make the plot

```


Let's create a different type of plot. Let's say we want to compare someone's college year to their coding experience. How would we do that?
```{r}
# First, we have to summarise their coding experience by year.



# Now we can plot our means


```

Let's make this plot a little nicer looking.
```{r}

# we can also save a plot as a variable like this
plot <- 
  
# Let's also remove the NA



plot_without_na <- 
```
Now, let's try to see whether the state you are from predicts what you call soda!
```{r}
# First, clean the soda data again. Let's just call it soda or other. 


#Then, let's get the percentage by state. 
```

We can also save any plot using ggsave! (Be careful about overwriting plots though!)
```{r}

```
