---
title: "Exercise: Plotting with ggplot2"
author: "Rian DeFaccio"
date: "`r Sys.Date()`"
output: html_document
---

Before we jump into the questions, check your working directory and load any packages you think you'll need.

```{r}

```

### Question 1: Import Data and Initial Inspection

Import the data set we have supplied from the Behavioral Risk Factor Surveillance System (BRFSS). This is a small data set on smoking behavior in various areas. It is in the *data* folder:

> *data/BRFSS_Four_Level_Smoking_1995-2010.csv*

Examine the top and bottom of this data set.

```{r}

```

Also, what are the distinct values in the state column? For the next couple of questions we would like to have each row represent a distinct state or territory. If there are any observations that violate this idea, remove them from the data set now.

```{r}

```

### Question 2: Focus on One Year

We will practice some exploratory data analysis of continuous variables by focusing on a single year of smoking data.

1.  Save a data frame containing only data for the most recent year as a variable called `df_recent`. Confirm that this worked as expected.

```{r}
# what is the most recent year?

# get data for that year

```

### Question 3: Distribution of Never Smokers

Let's look at the distribution of "Never Smokers" in the most recent year of data. What type of plot(s) is appropriate to view this data? Build one or more plots below using `ggplot()`.

```{r}
# build plot(s) here

```

Let's also get some statistical summaries of the percent of never smokers in each state. Can you calculate the minimum, median, mean, and maximum values for percent of people who had never smoked in each state in the most recent year.

**NOTE:** Since we are working with summary data here, just be aware that we are asking for instance for the "mean percent of smokers in a state" and not the overall mean or percent of people who smoked in the U.S.

```{r}

```

### Question 4: Adjust Your Plot

Let's practice making some adjustments to our plot. Pick one of your previous plots and use it in this question.

First, change the color/fill of your plot. Pick your color from one of the following choices:

1.  Pick a pre-existing color from here: <https://bookdown.org/hneth/ds4psy/D-3-apx-colors-basics.html>
2.  Use a Hex-Color-Picker. Just Google "hex color picker" and create your own custom color! Hex codes should look like `#8ccf4e`.

What if you do a different color and fill???

```{r}

```

This time, while keeping your colors the same, adjust your x- and y- axis labels to look a little nicer. Go with something like:

-   "Number of States"
-   "Percent of Residents who Never Smoked"
-   Also add a title.

```{r}

```

Can you figure out how to center your title and use a serif font?

```{r}

```

Can you get your plot to look just like the image below?

![](images/lab_4_image_1.png){width="500"}

**HINT:** We used 25 bins for this histogram.

```{r}

```

### Question 5: Focus on 4 States

Let's just focus on the states that border the Pacific Ocean.

Begin by creating a new data frame called `df_west` which only has data for the states of Alaska, Washington, Oregon, and California. Take a look at this data frame.

```{r}

```

Now, make a density plot of the distribution of every day smokers, where the values for each state get mapped to a different color. Be sure to set the alpha parameter low enough that you can see all of the shapes.

```{r}

```

Let's view this again, but use a box plot this time. You can choose what variables should go on the x- versus the y- axis. Use the function `geom_boxplot()` to build a box plot. We'll learn more about box plots shortly.

```{r}

```

Now let's create a facet plot, with one facet for each state. Let's look of the percent of never smokers this time, and create a 2x2 facet plot where each facet shows the distribution of the percent of never smokers in the given state.

```{r}

```

Finally, we should really consider the dependence of the `Smoke.everyday` variable on time. We've produced an image of the desired plot here. At first just try to recreate the basic plot. If you have extra time, recreate as many of the stylistic elements as you can. Use the function `geom_line()` to build this plot.

![](images/lab_4_image_2.png){width="500"}

**HINT:** For the line plot to work properly, you will need to specify `group =` inside your call to `aes()`.

```{r}

```
