#Mammals sleep dataset ##loading the dataset

library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## filtering the dataset by piping it to check the relationship between total sleep and brainweight
msleep %>%
  select(c(1, 6, 7, 10, 11)) %>%
  filter(sleep_total < 5) %>%
  ggplot() + geom_line(aes(x = brainwt, y = sleep_total)) + labs(title = "Efects of brain wight on sleep")
## Warning: Removed 3 row(s) containing missing values (geom_path).

mssleep_avg_genus =msleep %>%
  ## checking the average sleep_total and looking at the distribution between the names
  mutate(average_sleep_over = sleep_total -mean(sleep_total))%>%
  select(name, genus, sleep_total, bodywt, average_sleep_over) %>%
  arrange(average_sleep_over)
mssleep_avg_genus
## # A tibble: 83 × 5
##    name             genus         sleep_total bodywt average_sleep_over
##    <chr>            <chr>               <dbl>  <dbl>              <dbl>
##  1 Giraffe          Giraffa               1.9  900.               -8.53
##  2 Pilot whale      Globicephalus         2.7  800                -7.73
##  3 Horse            Equus                 2.9  521                -7.53
##  4 Roe deer         Capreolus             3     14.8              -7.43
##  5 Donkey           Equus                 3.1  187                -7.33
##  6 African elephant Loxodonta             3.3 6654                -7.13
##  7 Caspian seal     Phoca                 3.5   86                -6.93
##  8 Sheep            Ovis                  3.8   55.5              -6.63
##  9 Asian elephant   Elephas               3.9 2547                -6.53
## 10 Cow              Bos                   4    600                -6.43
## # … with 73 more rows
ggplot(data = mssleep_avg_genus) + geom_line(aes(x =bodywt , y = sleep_total), na.rm = T) + labs(title = " The effect of body weight on sleep total")

##how about the effect of body weight on sleep total? clearly it has an effect on the total sleep of mammals

asides the fact that girrafes have the lowest sleep per day and little brown bats, the highest, we can also see from the graphs that body weight and brain weight might be one of the contributors that influences the total sleep per day of mammals