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

In this challenge, you'll get the opportunity to plot data from the `iris` dataset. This is a classic dataset that comes with R — you may even have seen it referenced before, since it's commonly used to illustrate basic data science concepts. `iris` contains measurements of petal and sepal lengths/widths for different species of iris flowers.

1. Load tidyverse and your data. Make sure to save the `iris` dataset into a new variable (with a name of your choice).

```{r}
library(tidyverse)
```

```{r}
# load data
mydata <- iris
```

2. Inspect your data and understand:
a) the variables in your dataset and their data types
b) number of rows and columns

```{r}
head(mydata)
nrow(mydata)
ncol(mydata)
```

3. Plot a histogram using `ggplot` functions to look at the distributions of **sepal lengths (Sepal.Length)** and **petal lengths (Petal.Length)**. Also make sure to give the plot a title, and label the x axis.

HINT: you can use function `labs()` to give the plot a title, or label axis. 

```{r}
# sepal length
ggplot(data = mydata, aes(x = Sepal.Length)) +
  geom_histogram() +
  labs(x = 'sepal length (cm)', title = 'histogram of iris sepal lengths')

# petal length
ggplot(data = mydata, aes(x = Petal.Length)) +
  geom_histogram() +
  labs(x = 'petal length (cm)', title = 'histogram of iris petal lengths')
```

4. **Choose 1** of the histograms you made above, and play around with the number of bins to create a visualization you think best represents the data. (There's no right answer to this!)

Also change the fill and outline colors of the histogram, and pick a theme you like the look of (see here - https://ggplot2.tidyverse.org/reference/ggtheme.html - for the list of default ggplot themes).

HINT: you can use the argument `bins` to adjust bin size

```{r}
# sepal length
ggplot(data = mydata, aes(x = Sepal.Length)) +
  geom_histogram(bins = 15, fill = 'dodgerblue', color = 'dodgerblue4') +
  labs(x = 'sepal length (cm)', title = 'histogram of iris sepal lengths') +
  theme_bw()
```


5. Next, make a bar plot showing the mean petal length (Petal.Length) for the different iris species in our dataset (stored in the Species column). Make sure you add axis labels (x and y), and make each of the different bars a different color.

```{r}
ggplot(data = mydata, aes(x = Species, y = Petal.Length, fill = Species)) +
  geom_bar(stat = 'summary', fun.y = 'mean') +
  labs(x = 'iris species', y = 'petal length') +
  theme_bw()
```

6. Finally, compute the correlation between petal length and sepal length, describe the relationship in words, and visualize it using a scatterplot.

BONUS: Instead of changing the color of the points to a single color of your choice, you can make ggplot pick different colors based on the flower species. To do this, add `color = Species` into your `aes()` function.

```{r}
cor.test(mydata$Sepal.Length, mydata$Petal.Length)
# The correlation between sepal length and petal length is 0.87. This indicates that flowers with longer sepal lengths also tend to have longer petals.

ggplot(data = mydata, aes(x = Sepal.Length, y = Petal.Length)) +
  geom_point(size = 2, alpha = 0.5, color = 'plum4') +
  labs(x = 'iris species', y = 'petal length') +
  theme_bw()

# bonus
ggplot(data = mydata, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
  geom_point(size = 2, alpha = 0.5) +
  labs(x = 'iris species', y = 'petal length') +
  theme_bw()
```


