Instructions

Refer to the detailed instructions for this assignment in Brightspace.

Data Import

Don’t alter the three code chunks in this section. First we read in the two data sets and deleting missing values.

library(tidyverse)
fluoride <- read_csv("http://jamessuleiman.com/teaching/datasets/fluoride.csv")
fluoride <- fluoride %>% drop_na()
arsenic <- read_csv("http://jamessuleiman.com/teaching/datasets/arsenic.csv")
arsenic <- arsenic %>% drop_na()

Next we display the first few rows of fluoride.

head(fluoride)
## # A tibble: 6 × 6
##   location  n_wells_tested percent_wells_above_guideline median percen…¹ maximum
##   <chr>              <dbl>                         <dbl>  <dbl>    <dbl>   <dbl>
## 1 Otis                  60                          30    1.13      3.2      3.6
## 2 Dedham               102                          22.5  0.94      3.27     7  
## 3 Denmark               46                          19.6  0.45      3.15     3.9
## 4 Surry                175                          18.3  0.8       3.52     6.9
## 5 Prospect              57                          17.5  0.785     2.5      2.7
## 6 Eastbrook             31                          16.1  1.29      2.44     3.3
## # … with abbreviated variable name ¹​percentile_95

Then we display the first few rows of arsenic.

head(arsenic)
## # A tibble: 6 × 6
##   location       n_wells_tested percent_wells_above_gui…¹ median perce…² maximum
##   <chr>                   <dbl>                     <dbl>  <dbl>   <dbl>   <dbl>
## 1 Manchester                275                      58.9   14      93       200
## 2 Gorham                    467                      50.1   10.5   130       460
## 3 Columbia                   42                      50      9.8    65.9     200
## 4 Monmouth                  277                      49.5   10     110       368
## 5 Eliot                      73                      49.3    9.7    41.4      45
## 6 Columbia Falls             25                      48      8.1    53.8      71
## # … with abbreviated variable names ¹​percent_wells_above_guideline,
## #   ²​percentile_95

Join data

In the code chunk below, create a new tibble called chemicals that joins fluoride and arsenic. You probably want to do an inner join but the join type is up to you.

chemicals <- fluoride %>% inner_join(arsenic, by = "location")

The next code chunk displays the head of your newly created chemicals tibble. Take a look to verify that your join looks ok.

head(chemicals)
## # A tibble: 6 × 11
##   location  n_wells_te…¹ perce…² media…³ perce…⁴ maxim…⁵ n_wel…⁶ perce…⁷ media…⁸
##   <chr>            <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
## 1 Otis                60    30     1.13     3.2      3.6      53    39.6    4.8 
## 2 Dedham             102    22.5   0.94     3.27     7        97    17.5    1   
## 3 Denmark             46    19.6   0.45     3.15     3.9      42     0      0.25
## 4 Surry              175    18.3   0.8      3.52     6.9     181    40.3    6   
## 5 Prospect            57    17.5   0.785    2.5      2.7      50     4      1   
## 6 Eastbrook           31    16.1   1.29     2.44     3.3      28    10.7    1.5 
## # … with 2 more variables: percentile_95.y <dbl>, maximum.y <dbl>, and
## #   abbreviated variable names ¹​n_wells_tested.x,
## #   ²​percent_wells_above_guideline.x, ³​median.x, ⁴​percentile_95.x, ⁵​maximum.x,
## #   ⁶​n_wells_tested.y, ⁷​percent_wells_above_guideline.y, ⁸​median.y

Intersting subset

In the code chunk below create an interesting subset of the data. You’ll likely find an interesting subset by filtering for locations that have high or low levels of arsenic, flouride, or both.

toparsenic <- chemicals %>% select(location, percent_wells_above_guideline.y) %>% top_n(5) %>% arrange(desc(percent_wells_above_guideline.y))
## Selecting by percent_wells_above_guideline.y
toparsenic
## # A tibble: 5 × 2
##   location   percent_wells_above_guideline.y
##   <chr>                                <dbl>
## 1 Manchester                            58.9
## 2 Gorham                                50.1
## 3 Columbia                              50  
## 4 Monmouth                              49.5
## 5 Eliot                                 49.3

I wanted to know which towns has the highest arsenic levels. I originally looked at all above 25%, but decided to just take the top 5 results instead.

Display the first few rows of your interesting subset in the code chunk below.

head(toparsenic)
## # A tibble: 5 × 2
##   location   percent_wells_above_guideline.y
##   <chr>                                <dbl>
## 1 Manchester                            58.9
## 2 Gorham                                50.1
## 3 Columbia                              50  
## 4 Monmouth                              49.5
## 5 Eliot                                 49.3

Visualize your subset

In the code chunk below, create a ggplot visualization of your subset that is fairly simple for a viewer to comprehend.

ggplot(data = toparsenic, aes(x = location, y = percent_wells_above_guideline.y)) +
  geom_bar(stat = "identity", fill ="blue") +
  coord_flip() +
  ggtitle("Top Arsenic Level Towns") +
  xlab("Location") +
  ylab("Percentage of Wells Above Max Level")

Once you are done, knit, publish, and then submit your link to your published RPubs document in Brightspace.