---
title: "Activity 3 & 4"
author: "Jonathan W. Duggins" 
date: "August 9, 2023"
output:
  html_document:
    toc: true
    toc_float: true
    code_folding: hide
---

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

## Activity #3

```{r,echo=TRUE}
#2
table(iris$Species)

#3
fivenum(iris$Sepal.Length)
fivenum(iris$Petal.Length)

#4
iris %>% summarise(meanSW = mean(Sepal.Width),
                   sdSW = sd(Sepal.Width),
                   meanPW = mean(Petal.Width),
                   sdPW = sd(Petal.Width)
                   )

#5
iris %>% select(where(is.numeric)) %>% cor(method="spearman")

#6
table((iris$Sepal.Length<=5.8),iris$Species)

#7
iris[abs(iris$Sepal.Length - mean(iris$Sepal.Length))>2*sd(iris$Sepal.Length),]
```

## Activity #4

```{r, echo = TRUE, eval = TRUE, fig.dim=c(8,4)}
#Graph 1
s<-starwars %>% subset(species != "NA" & species != "Human") 
ggplot(data = s, aes(y=species)) + 
  geom_bar(fill="lightblue", color="black")
```

```{r, echo = TRUE, eval = TRUE, message = FALSE}
#Graph 2
ggplot(data = iris, aes(x=Sepal.Length)) + 
  geom_density(aes(color=Species, fill=Species), alpha = 0.5) + 
  geom_histogram(aes(y=after_stat(density)), alpha=0.5)

```

```{r, echo = TRUE, eval = TRUE, message = FALSE}
#Graph 3
ggplot(data = iris, aes(x=Sepal.Length, y=Sepal.Width)) +
  geom_point(aes(color=Species, shape=Species)) + 
  labs(x="Sepal Length",y="Sepal Width",title="Sepal Length vs Width with Simple Linear Model", subtitle="Grouped by Species") + 
  geom_smooth(method = lm, aes(color=Species)) + 
  scale_shape_discrete(labels=c("Setosa", "Versicolor", "Virginica")) + 
  scale_color_discrete(labels=c("Setosa", "Versicolor", "Virginica"))
```