Overview

The dataset contains information about cats in the UK that were tracked using GPS sensors. It includes details such as sensor measurements, cat characteristics, and additional reference information. The original dataset can be seen via this link. In this project, it is aimed to examine the behaviors of cats such as hunting, spending time in the environment, and food preference by using the variables in these 2 csv files (cats_uk.csv, cats_uk_reference.csv)

Analysis Questios

1.) Question 1: What are the most actively tracked pet cats based on the number of recorded events, and can we identify the top 20 cats with the highest event counts?

  1. Question 2: Whats the average of the pet cats’ age?

  2. Question 3: What is the distribution of average ground speed for neutered and adult cats?

  3. Question 4: What are the hunting statistics of house cats according to seasons?

  4. Question 5: How does the time cats spend at home vary depending on the number of cats living at home and their sex?

  5. Question 6: How does the average number of preys of cats vary according to month and gender?

  6. Question 7: What is the latitude and longitude distribution of the 10 tag_ids with the highest ground speed?

  7. Question 8: What is the distribution of the number of observations according to age and gender?

  8. Question 9: How do food preferences of house cats vary according to gender?

  9. Question 10: How does the ellipsoid distribution of ground speed and height above vary according to season and being neutered?

Loading Libraries and Data

# Load necessary libraries
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
library(data.table)
## 
## Attaching package: 'data.table'
## The following objects are masked from 'package:dplyr':
## 
##     between, first, last
library(RColorBrewer)

Reading the data from github

cats_uk <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-01-31/cats_uk.csv')
## Rows: 18215 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (2): tag_id, study_name
## dbl  (5): event_id, location_long, location_lat, ground_speed, height_above_...
## lgl  (3): visible, algorithm_marked_outlier, manually_marked_outlier
## dttm (1): timestamp
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
cats_uk_reference <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-01-31/cats_uk_reference.csv')
## Rows: 101 Columns: 16
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (6): tag_id, animal_id, animal_taxon, animal_reproductive_condition, an...
## dbl  (4): prey_p_month, hrs_indoors, n_cats, age_years
## lgl  (4): hunt, food_dry, food_wet, food_other
## dttm (2): deploy_on_date, deploy_off_date
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Merging the 2 datasets based on the tag_id variable

merged_cats <- inner_join(cats_uk, cats_uk_reference, by = "tag_id")
merged_cats
## # A tibble: 18,215 × 26
##    tag_id   event_id visible timestamp           location_long location_lat
##    <chr>       <dbl> <lgl>   <dttm>                      <dbl>        <dbl>
##  1 Ares   3395610551 TRUE    2017-06-24 01:03:57         -5.11         50.2
##  2 Ares   3395610552 TRUE    2017-06-24 01:11:20         -5.11         50.2
##  3 Ares   3395610553 TRUE    2017-06-24 02:58:16         -5.11         50.2
##  4 Ares   3395610554 TRUE    2017-06-24 03:01:26         -5.11         50.2
##  5 Ares   3395610555 TRUE    2017-06-24 03:51:58         -5.11         50.2
##  6 Ares   3395610556 TRUE    2017-06-24 03:55:03         -5.11         50.2
##  7 Ares   3395610557 TRUE    2017-06-24 05:24:17         -5.11         50.2
##  8 Ares   3395610558 TRUE    2017-06-24 05:27:23         -5.11         50.2
##  9 Ares   3395610559 TRUE    2017-06-24 09:14:37         -5.11         50.2
## 10 Ares   3395610560 TRUE    2017-06-24 09:17:42         -5.11         50.2
## # ℹ 18,205 more rows
## # ℹ 20 more variables: ground_speed <dbl>, height_above_ellipsoid <dbl>,
## #   algorithm_marked_outlier <lgl>, manually_marked_outlier <lgl>,
## #   study_name <chr>, animal_id <chr>, animal_taxon <chr>,
## #   deploy_on_date <dttm>, deploy_off_date <dttm>, hunt <lgl>,
## #   prey_p_month <dbl>, animal_reproductive_condition <chr>, animal_sex <chr>,
## #   hrs_indoors <dbl>, n_cats <dbl>, food_dry <lgl>, food_wet <lgl>, …

Creating a data table by using merged datasets

merged_cats <- data.table(merged_cats)
merged_cats
##            tag_id   event_id visible           timestamp location_long
##     1:       Ares 3395610551    TRUE 2017-06-24 01:03:57     -5.113851
##     2:       Ares 3395610552    TRUE 2017-06-24 01:11:20     -5.113851
##     3:       Ares 3395610553    TRUE 2017-06-24 02:58:16     -5.113730
##     4:       Ares 3395610554    TRUE 2017-06-24 03:01:26     -5.113774
##     5:       Ares 3395610555    TRUE 2017-06-24 03:51:58     -5.114247
##    ---                                                                
## 18211: Millie-Tag 4149497976    TRUE 2017-11-26 15:37:52     -4.521489
## 18212: Millie-Tag 4149497977    TRUE 2017-11-26 15:40:59     -4.521498
## 18213: Millie-Tag 4149497978    TRUE 2017-11-26 16:27:31     -4.521803
## 18214: Millie-Tag 4149497979    TRUE 2017-11-26 16:34:26     -4.521946
## 18215: Millie-Tag 4149497980    TRUE 2017-11-27 00:09:29     -4.522027
##        location_lat ground_speed height_above_ellipsoid
##     1:     50.17032          684                 154.67
##     2:     50.17032          936                 154.67
##     3:     50.16988         2340                  81.35
##     4:     50.16983            0                  67.82
##     5:     50.17014         4896                 118.03
##    ---                                                 
## 18211:     50.86932         1260                 144.66
## 18212:     50.86929        16380                 136.60
## 18213:     50.86944         4500                 160.97
## 18214:     50.86939         1044                 179.81
## 18215:     50.86953          792                 151.67
##        algorithm_marked_outlier manually_marked_outlier              study_name
##     1:                    FALSE                   FALSE Pet Cats United Kingdom
##     2:                    FALSE                   FALSE Pet Cats United Kingdom
##     3:                    FALSE                   FALSE Pet Cats United Kingdom
##     4:                    FALSE                   FALSE Pet Cats United Kingdom
##     5:                    FALSE                   FALSE Pet Cats United Kingdom
##    ---                                                                         
## 18211:                    FALSE                   FALSE Pet Cats United Kingdom
## 18212:                    FALSE                   FALSE Pet Cats United Kingdom
## 18213:                    FALSE                   FALSE Pet Cats United Kingdom
## 18214:                    FALSE                   FALSE Pet Cats United Kingdom
## 18215:                    FALSE                   FALSE Pet Cats United Kingdom
##        animal_id animal_taxon      deploy_on_date     deploy_off_date hunt
##     1:      Ares  Felis catus 2017-06-24 01:03:57 2017-06-30 23:58:01   NA
##     2:      Ares  Felis catus 2017-06-24 01:03:57 2017-06-30 23:58:01   NA
##     3:      Ares  Felis catus 2017-06-24 01:03:57 2017-06-30 23:58:01   NA
##     4:      Ares  Felis catus 2017-06-24 01:03:57 2017-06-30 23:58:01   NA
##     5:      Ares  Felis catus 2017-06-24 01:03:57 2017-06-30 23:58:01   NA
##    ---                                                                    
## 18211:    Millie  Felis catus 2017-11-20 01:38:55 2017-11-27 00:09:29 TRUE
## 18212:    Millie  Felis catus 2017-11-20 01:38:55 2017-11-27 00:09:29 TRUE
## 18213:    Millie  Felis catus 2017-11-20 01:38:55 2017-11-27 00:09:29 TRUE
## 18214:    Millie  Felis catus 2017-11-20 01:38:55 2017-11-27 00:09:29 TRUE
## 18215:    Millie  Felis catus 2017-11-20 01:38:55 2017-11-27 00:09:29 TRUE
##        prey_p_month animal_reproductive_condition animal_sex hrs_indoors n_cats
##     1:          0.0                      Neutered          m         7.5      2
##     2:          0.0                      Neutered          m         7.5      2
##     3:          0.0                      Neutered          m         7.5      2
##     4:          0.0                      Neutered          m         7.5      2
##     5:          0.0                      Neutered          m         7.5      2
##    ---                                                                         
## 18211:          7.5                        Spayed          f        12.5      2
## 18212:          7.5                        Spayed          f        12.5      2
## 18213:          7.5                        Spayed          f        12.5      2
## 18214:          7.5                        Spayed          f        12.5      2
## 18215:          7.5                        Spayed          f        12.5      2
##        food_dry food_wet food_other study_site age_years
##     1:     TRUE     TRUE      FALSE         UK         3
##     2:     TRUE     TRUE      FALSE         UK         3
##     3:     TRUE     TRUE      FALSE         UK         3
##     4:     TRUE     TRUE      FALSE         UK         3
##     5:     TRUE     TRUE      FALSE         UK         3
##    ---                                                  
## 18211:    FALSE     TRUE       TRUE         UK         3
## 18212:    FALSE     TRUE       TRUE         UK         3
## 18213:    FALSE     TRUE       TRUE         UK         3
## 18214:    FALSE     TRUE       TRUE         UK         3
## 18215:    FALSE     TRUE       TRUE         UK         3

Exploratory Data Analysis

Task 1: Dropping rows where there are outliers (algorithm_marked_outlier=true and manually_marked_outlier=true)

filtered_cats <- merged_cats[!(algorithm_marked_outlier & manually_marked_outlier), ]

Task 2: Dropping rows where food_other=true

filtered_cats <- filtered_cats[food_other == FALSE, ]

Question 1: What are the most actively tracked pet cats based on the number of recorded events, and can we identify the top 20 cats with the highest event counts?

Task 3: Count the number of events per tag_id and find the top 20 tags with the highest event count

event_count_per_tag <- filtered_cats[, .(event_count = .N), by = tag_id]
top_20_tags <- event_count_per_tag[order(-event_count)][1:20]
top_20_tags
##                  tag_id event_count
##  1:           Teddy-Tag         791
##  2:           Bella-Tag         318
##  3: Lightening Bugg-Tag         302
##  4:          Winnie-Tag         279
##  5:           Mifty-Tag         261
##  6:          Marley-Tag         260
##  7:          Keegan-Tag         252
##  8:             Charlie         242
##  9:             Max-Tag         241
## 10:         Dexter2-Tag         232
## 11:          Dexter-Tag         229
## 12:  Macaulay Mccat-Tag         228
## 13:                Lola         224
## 14:             Seb-Tag         217
## 15:           Missy-Tag         211
## 16:              CJ-Tag         198
## 17:         Carrots-Tag         197
## 18:         Siberia-Tag         190
## 19:           Binky-Tag         184
## 20:          Merlin-Tag         184

Question 2: Whats the average of the pet cats’ age?

Task 4:Calculating the mean age

mean_age <- mean(filtered_cats$age_years, na.rm = TRUE)
mean_age
## [1] 5.011255

Task 5: Creating a new column ‘is_adult’ categorizing cats equal to or older than the mean age as adult

filtered_cats$is_adult <- ifelse(filtered_cats$age_years >= mean_age, TRUE, FALSE)
filtered_cats$is_young <- ifelse(filtered_cats$age_years < mean_age, TRUE, FALSE)
filtered_cats
##        tag_id   event_id visible           timestamp location_long location_lat
##    1:    Ares 3395610551    TRUE 2017-06-24 01:03:57     -5.113851     50.17032
##    2:    Ares 3395610552    TRUE 2017-06-24 01:11:20     -5.113851     50.17032
##    3:    Ares 3395610553    TRUE 2017-06-24 02:58:16     -5.113730     50.16988
##    4:    Ares 3395610554    TRUE 2017-06-24 03:01:26     -5.113774     50.16983
##    5:    Ares 3395610555    TRUE 2017-06-24 03:51:58     -5.114247     50.17014
##   ---                                                                          
## 8395: Seb-Tag 4149451326    TRUE 2017-11-30 00:29:18     -5.218778     50.23670
## 8396: Seb-Tag 4149451327    TRUE 2017-11-30 00:42:37     -5.218778     50.23670
## 8397: Seb-Tag 4149451328    TRUE 2017-11-30 00:46:15     -5.219236     50.23692
## 8398: Seb-Tag 4149451329    TRUE 2017-11-30 00:49:36     -5.219236     50.23692
## 8399: Seb-Tag 4149451330    TRUE 2017-11-30 00:52:55     -5.218777     50.23632
##       ground_speed height_above_ellipsoid algorithm_marked_outlier
##    1:          684                 154.67                    FALSE
##    2:          936                 154.67                    FALSE
##    3:         2340                  81.35                    FALSE
##    4:            0                  67.82                    FALSE
##    5:         4896                 118.03                    FALSE
##   ---                                                             
## 8395:         3060                 116.41                    FALSE
## 8396:         3060                 116.41                    FALSE
## 8397:         1116                 139.00                    FALSE
## 8398:         1116                 139.00                    FALSE
## 8399:         1188                 126.60                    FALSE
##       manually_marked_outlier              study_name animal_id animal_taxon
##    1:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    2:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    3:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    4:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    5:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##   ---                                                                       
## 8395:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8396:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8397:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8398:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8399:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
##            deploy_on_date     deploy_off_date hunt prey_p_month
##    1: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    2: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    3: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    4: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    5: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##   ---                                                          
## 8395: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8396: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8397: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8398: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8399: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
##       animal_reproductive_condition animal_sex hrs_indoors n_cats food_dry
##    1:                      Neutered          m         7.5      2     TRUE
##    2:                      Neutered          m         7.5      2     TRUE
##    3:                      Neutered          m         7.5      2     TRUE
##    4:                      Neutered          m         7.5      2     TRUE
##    5:                      Neutered          m         7.5      2     TRUE
##   ---                                                                     
## 8395:                      Neutered          m        12.5      2     TRUE
## 8396:                      Neutered          m        12.5      2     TRUE
## 8397:                      Neutered          m        12.5      2     TRUE
## 8398:                      Neutered          m        12.5      2     TRUE
## 8399:                      Neutered          m        12.5      2     TRUE
##       food_wet food_other study_site age_years is_adult is_young
##    1:     TRUE      FALSE         UK         3    FALSE     TRUE
##    2:     TRUE      FALSE         UK         3    FALSE     TRUE
##    3:     TRUE      FALSE         UK         3    FALSE     TRUE
##    4:     TRUE      FALSE         UK         3    FALSE     TRUE
##    5:     TRUE      FALSE         UK         3    FALSE     TRUE
##   ---                                                           
## 8395:    FALSE      FALSE         UK         3    FALSE     TRUE
## 8396:    FALSE      FALSE         UK         3    FALSE     TRUE
## 8397:    FALSE      FALSE         UK         3    FALSE     TRUE
## 8398:    FALSE      FALSE         UK         3    FALSE     TRUE
## 8399:    FALSE      FALSE         UK         3    FALSE     TRUE

Task 6: Creating a new column ‘is_neutered’ based on animal_reproductive_condition

filtered_cats$is_neutered <- ifelse(filtered_cats$animal_reproductive_condition == "Neutered", TRUE, FALSE)
filtered_cats
##        tag_id   event_id visible           timestamp location_long location_lat
##    1:    Ares 3395610551    TRUE 2017-06-24 01:03:57     -5.113851     50.17032
##    2:    Ares 3395610552    TRUE 2017-06-24 01:11:20     -5.113851     50.17032
##    3:    Ares 3395610553    TRUE 2017-06-24 02:58:16     -5.113730     50.16988
##    4:    Ares 3395610554    TRUE 2017-06-24 03:01:26     -5.113774     50.16983
##    5:    Ares 3395610555    TRUE 2017-06-24 03:51:58     -5.114247     50.17014
##   ---                                                                          
## 8395: Seb-Tag 4149451326    TRUE 2017-11-30 00:29:18     -5.218778     50.23670
## 8396: Seb-Tag 4149451327    TRUE 2017-11-30 00:42:37     -5.218778     50.23670
## 8397: Seb-Tag 4149451328    TRUE 2017-11-30 00:46:15     -5.219236     50.23692
## 8398: Seb-Tag 4149451329    TRUE 2017-11-30 00:49:36     -5.219236     50.23692
## 8399: Seb-Tag 4149451330    TRUE 2017-11-30 00:52:55     -5.218777     50.23632
##       ground_speed height_above_ellipsoid algorithm_marked_outlier
##    1:          684                 154.67                    FALSE
##    2:          936                 154.67                    FALSE
##    3:         2340                  81.35                    FALSE
##    4:            0                  67.82                    FALSE
##    5:         4896                 118.03                    FALSE
##   ---                                                             
## 8395:         3060                 116.41                    FALSE
## 8396:         3060                 116.41                    FALSE
## 8397:         1116                 139.00                    FALSE
## 8398:         1116                 139.00                    FALSE
## 8399:         1188                 126.60                    FALSE
##       manually_marked_outlier              study_name animal_id animal_taxon
##    1:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    2:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    3:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    4:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    5:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##   ---                                                                       
## 8395:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8396:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8397:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8398:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8399:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
##            deploy_on_date     deploy_off_date hunt prey_p_month
##    1: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    2: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    3: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    4: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    5: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##   ---                                                          
## 8395: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8396: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8397: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8398: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8399: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
##       animal_reproductive_condition animal_sex hrs_indoors n_cats food_dry
##    1:                      Neutered          m         7.5      2     TRUE
##    2:                      Neutered          m         7.5      2     TRUE
##    3:                      Neutered          m         7.5      2     TRUE
##    4:                      Neutered          m         7.5      2     TRUE
##    5:                      Neutered          m         7.5      2     TRUE
##   ---                                                                     
## 8395:                      Neutered          m        12.5      2     TRUE
## 8396:                      Neutered          m        12.5      2     TRUE
## 8397:                      Neutered          m        12.5      2     TRUE
## 8398:                      Neutered          m        12.5      2     TRUE
## 8399:                      Neutered          m        12.5      2     TRUE
##       food_wet food_other study_site age_years is_adult is_young is_neutered
##    1:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##    2:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##    3:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##    4:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##    5:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##   ---                                                                       
## 8395:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE
## 8396:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE
## 8397:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE
## 8398:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE
## 8399:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE

Question 3: What is the distribution of average ground speed for neutered and adult cats?

Task 7: Groupping by is_neutered and is_adult acc. to mean of ground speed and draw a stacked bar chart without NA values

neutered_adult_speed <- filtered_cats %>%
  na.omit() %>%  # removing rows with NA values
  group_by(is_neutered, is_adult) %>%
  summarise(mean_speed = mean(ground_speed, na.rm = TRUE)) %>%
  ggplot(aes(x = is_neutered, y = mean_speed, fill = is_adult)) +
  geom_bar(stat = "identity") +
  geom_text(aes(label = round(mean_speed, 2)), position = position_stack(vjust = 0.5)) +  # add labels
  labs(title = "Mean Ground Speed",
       x = "Is Neutered",
       y = "Mean Ground Speed (m/s)",
       fill = "Is Adult") +
  theme(panel.grid = element_blank(), axis.text.y = element_blank(),                                                          panel.border                    = element_blank(), axis.ticks.y = element_blank(),plot.title = element_text(hjust = 0.5, color = "blue"), axis.title.y = element_blank())
## `summarise()` has grouped output by 'is_neutered'. You can override using the
## `.groups` argument.
neutered_adult_speed

>>> It can be inferred that neutered cats are faster than non-neutered ones and that adult cats are faster than young one

Question 4: What are the hunting statistics of house cats according to seasons?

Task 8: Converting timestamp to a POSIXct object. POSIXct provides a way to store date and time information with sub-second precision.

filtered_cats$timestamp <- as.POSIXct(filtered_cats$timestamp)
filtered_cats
##        tag_id   event_id visible           timestamp location_long location_lat
##    1:    Ares 3395610551    TRUE 2017-06-24 01:03:57     -5.113851     50.17032
##    2:    Ares 3395610552    TRUE 2017-06-24 01:11:20     -5.113851     50.17032
##    3:    Ares 3395610553    TRUE 2017-06-24 02:58:16     -5.113730     50.16988
##    4:    Ares 3395610554    TRUE 2017-06-24 03:01:26     -5.113774     50.16983
##    5:    Ares 3395610555    TRUE 2017-06-24 03:51:58     -5.114247     50.17014
##   ---                                                                          
## 8395: Seb-Tag 4149451326    TRUE 2017-11-30 00:29:18     -5.218778     50.23670
## 8396: Seb-Tag 4149451327    TRUE 2017-11-30 00:42:37     -5.218778     50.23670
## 8397: Seb-Tag 4149451328    TRUE 2017-11-30 00:46:15     -5.219236     50.23692
## 8398: Seb-Tag 4149451329    TRUE 2017-11-30 00:49:36     -5.219236     50.23692
## 8399: Seb-Tag 4149451330    TRUE 2017-11-30 00:52:55     -5.218777     50.23632
##       ground_speed height_above_ellipsoid algorithm_marked_outlier
##    1:          684                 154.67                    FALSE
##    2:          936                 154.67                    FALSE
##    3:         2340                  81.35                    FALSE
##    4:            0                  67.82                    FALSE
##    5:         4896                 118.03                    FALSE
##   ---                                                             
## 8395:         3060                 116.41                    FALSE
## 8396:         3060                 116.41                    FALSE
## 8397:         1116                 139.00                    FALSE
## 8398:         1116                 139.00                    FALSE
## 8399:         1188                 126.60                    FALSE
##       manually_marked_outlier              study_name animal_id animal_taxon
##    1:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    2:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    3:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    4:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    5:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##   ---                                                                       
## 8395:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8396:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8397:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8398:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8399:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
##            deploy_on_date     deploy_off_date hunt prey_p_month
##    1: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    2: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    3: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    4: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    5: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##   ---                                                          
## 8395: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8396: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8397: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8398: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8399: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
##       animal_reproductive_condition animal_sex hrs_indoors n_cats food_dry
##    1:                      Neutered          m         7.5      2     TRUE
##    2:                      Neutered          m         7.5      2     TRUE
##    3:                      Neutered          m         7.5      2     TRUE
##    4:                      Neutered          m         7.5      2     TRUE
##    5:                      Neutered          m         7.5      2     TRUE
##   ---                                                                     
## 8395:                      Neutered          m        12.5      2     TRUE
## 8396:                      Neutered          m        12.5      2     TRUE
## 8397:                      Neutered          m        12.5      2     TRUE
## 8398:                      Neutered          m        12.5      2     TRUE
## 8399:                      Neutered          m        12.5      2     TRUE
##       food_wet food_other study_site age_years is_adult is_young is_neutered
##    1:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##    2:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##    3:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##    4:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##    5:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##   ---                                                                       
## 8395:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE
## 8396:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE
## 8397:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE
## 8398:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE
## 8399:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE

Task 9: Creating a new column ‘month’ extracting month from timestamp

filtered_cats$month <- format(filtered_cats$timestamp, "%m")
filtered_cats$month <- as.numeric(filtered_cats$month[grepl("^\\d+$", filtered_cats$month)])
filtered_cats
##        tag_id   event_id visible           timestamp location_long location_lat
##    1:    Ares 3395610551    TRUE 2017-06-24 01:03:57     -5.113851     50.17032
##    2:    Ares 3395610552    TRUE 2017-06-24 01:11:20     -5.113851     50.17032
##    3:    Ares 3395610553    TRUE 2017-06-24 02:58:16     -5.113730     50.16988
##    4:    Ares 3395610554    TRUE 2017-06-24 03:01:26     -5.113774     50.16983
##    5:    Ares 3395610555    TRUE 2017-06-24 03:51:58     -5.114247     50.17014
##   ---                                                                          
## 8395: Seb-Tag 4149451326    TRUE 2017-11-30 00:29:18     -5.218778     50.23670
## 8396: Seb-Tag 4149451327    TRUE 2017-11-30 00:42:37     -5.218778     50.23670
## 8397: Seb-Tag 4149451328    TRUE 2017-11-30 00:46:15     -5.219236     50.23692
## 8398: Seb-Tag 4149451329    TRUE 2017-11-30 00:49:36     -5.219236     50.23692
## 8399: Seb-Tag 4149451330    TRUE 2017-11-30 00:52:55     -5.218777     50.23632
##       ground_speed height_above_ellipsoid algorithm_marked_outlier
##    1:          684                 154.67                    FALSE
##    2:          936                 154.67                    FALSE
##    3:         2340                  81.35                    FALSE
##    4:            0                  67.82                    FALSE
##    5:         4896                 118.03                    FALSE
##   ---                                                             
## 8395:         3060                 116.41                    FALSE
## 8396:         3060                 116.41                    FALSE
## 8397:         1116                 139.00                    FALSE
## 8398:         1116                 139.00                    FALSE
## 8399:         1188                 126.60                    FALSE
##       manually_marked_outlier              study_name animal_id animal_taxon
##    1:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    2:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    3:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    4:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##    5:                   FALSE Pet Cats United Kingdom      Ares  Felis catus
##   ---                                                                       
## 8395:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8396:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8397:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8398:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
## 8399:                   FALSE Pet Cats United Kingdom       Seb  Felis catus
##            deploy_on_date     deploy_off_date hunt prey_p_month
##    1: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    2: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    3: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    4: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##    5: 2017-06-24 01:03:57 2017-06-30 23:58:01   NA            0
##   ---                                                          
## 8395: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8396: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8397: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8398: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
## 8399: 2017-11-24 09:43:09 2017-11-30 00:52:55 TRUE            3
##       animal_reproductive_condition animal_sex hrs_indoors n_cats food_dry
##    1:                      Neutered          m         7.5      2     TRUE
##    2:                      Neutered          m         7.5      2     TRUE
##    3:                      Neutered          m         7.5      2     TRUE
##    4:                      Neutered          m         7.5      2     TRUE
##    5:                      Neutered          m         7.5      2     TRUE
##   ---                                                                     
## 8395:                      Neutered          m        12.5      2     TRUE
## 8396:                      Neutered          m        12.5      2     TRUE
## 8397:                      Neutered          m        12.5      2     TRUE
## 8398:                      Neutered          m        12.5      2     TRUE
## 8399:                      Neutered          m        12.5      2     TRUE
##       food_wet food_other study_site age_years is_adult is_young is_neutered
##    1:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##    2:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##    3:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##    4:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##    5:     TRUE      FALSE         UK         3    FALSE     TRUE        TRUE
##   ---                                                                       
## 8395:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE
## 8396:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE
## 8397:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE
## 8398:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE
## 8399:    FALSE      FALSE         UK         3    FALSE     TRUE        TRUE
##       month
##    1:     6
##    2:     6
##    3:     6
##    4:     6
##    5:     6
##   ---      
## 8395:    11
## 8396:    11
## 8397:    11
## 8398:    11
## 8399:    11

Task 10: Creating a new column ‘season’ categorizing months into seasons.

filtered_cats$season <- cut(as.numeric(filtered_cats$month),
                            breaks = c(0, 3, 6, 9, 12),
                            labels = c("Winter", "Spring", "Summer", "Fall"),
                            include.lowest = TRUE)

Task 11: Groupping by season and calculate prey_p_month statistics

season_prey_stats <- filtered_cats %>%
  group_by(season) %>%
  summarise(mean_prey = mean(prey_p_month),
            median_prey = median(prey_p_month),
            min_prey = min(prey_p_month),
            max_prey = max(prey_p_month))

season_prey_stats
## # A tibble: 3 × 5
##   season mean_prey median_prey min_prey max_prey
##   <fct>      <dbl>       <dbl>    <dbl>    <dbl>
## 1 Spring      3.93         3          0     12.5
## 2 Summer      3.45         0.5        0     17.5
## 3 Fall        4.29         3          0     17.5

>>> It can be said that, on average, house cats hunt the most in autumn, and there are no observations in winter.

Question 5: How does the time cats spend at home vary depending on the number of cats living at home and their sex?

theme_set(theme_minimal())

Task 12: Group hrs_indoors by n_cats and draw a bar chart Group hrs_indoors by n_cats and animal_sex

hrs_indoors_by_cats_sex <- filtered_cats %>%
  group_by(n_cats, animal_sex) %>%
  summarise(mean_hrs_indoors = mean(hrs_indoors, na.rm = TRUE))
## `summarise()` has grouped output by 'n_cats'. You can override using the
## `.groups` argument.
hrs_indoors_by_cats <- ggplot(hrs_indoors_by_cats_sex, aes(x = mean_hrs_indoors, y = as.factor(n_cats),                                fill = animal_sex)) +
  geom_bar(stat = "identity", position = "dodge") +
  geom_text(aes(label = round(mean_hrs_indoors, 2)), 
            position = position_dodge(width = 0.9), 
            vjust = -0.5, 
            color = "black") +  # add labels
  labs(title = "Hours Indoors by Number of Cats and Sex",
       x = "Mean Hours Indoors",
       y = "Number of Cats",
       fill = "Animal Sex") +
  theme(plot.title =  element_text(hjust = 0.5, color = "blue"), panel.grid = element_blank(), panel.border = element_blank(), axis.text.x                       = element_blank(), axis.ticks.x = element_blank())
  theme_minimal() 
## List of 97
##  $ line                      :List of 6
##   ..$ colour       : chr "black"
##   ..$ linewidth    : num 0.5
##   ..$ linetype     : num 1
##   ..$ lineend      : chr "butt"
##   ..$ arrow        : logi FALSE
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_line" "element"
##  $ rect                      :List of 5
##   ..$ fill         : chr "white"
##   ..$ colour       : chr "black"
##   ..$ linewidth    : num 0.5
##   ..$ linetype     : num 1
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_rect" "element"
##  $ text                      :List of 11
##   ..$ family       : chr ""
##   ..$ face         : chr "plain"
##   ..$ colour       : chr "black"
##   ..$ size         : num 11
##   ..$ hjust        : num 0.5
##   ..$ vjust        : num 0.5
##   ..$ angle        : num 0
##   ..$ lineheight   : num 0.9
##   ..$ margin       : 'margin' num [1:4] 0points 0points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : logi FALSE
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ title                     : NULL
##  $ aspect.ratio              : NULL
##  $ axis.title                : NULL
##  $ axis.title.x              :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 1
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 2.75points 0points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.x.top          :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 0
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 0points 2.75points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.x.bottom       : NULL
##  $ axis.title.y              :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 1
##   ..$ angle        : num 90
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 2.75points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.y.left         : NULL
##  $ axis.title.y.right        :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 0
##   ..$ angle        : num -90
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 0points 0points 2.75points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text                 :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : chr "grey30"
##   ..$ size         : 'rel' num 0.8
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.x               :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 1
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 2.2points 0points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.x.top           :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 0
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 0points 2.2points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.x.bottom        : NULL
##  $ axis.text.y               :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 1
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 2.2points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.y.left          : NULL
##  $ axis.text.y.right         :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 0
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 0points 0points 2.2points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.ticks                : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ axis.ticks.x              : NULL
##  $ axis.ticks.x.top          : NULL
##  $ axis.ticks.x.bottom       : NULL
##  $ axis.ticks.y              : NULL
##  $ axis.ticks.y.left         : NULL
##  $ axis.ticks.y.right        : NULL
##  $ axis.ticks.length         : 'simpleUnit' num 2.75points
##   ..- attr(*, "unit")= int 8
##  $ axis.ticks.length.x       : NULL
##  $ axis.ticks.length.x.top   : NULL
##  $ axis.ticks.length.x.bottom: NULL
##  $ axis.ticks.length.y       : NULL
##  $ axis.ticks.length.y.left  : NULL
##  $ axis.ticks.length.y.right : NULL
##  $ axis.line                 : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ axis.line.x               : NULL
##  $ axis.line.x.top           : NULL
##  $ axis.line.x.bottom        : NULL
##  $ axis.line.y               : NULL
##  $ axis.line.y.left          : NULL
##  $ axis.line.y.right         : NULL
##  $ legend.background         : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ legend.margin             : 'margin' num [1:4] 5.5points 5.5points 5.5points 5.5points
##   ..- attr(*, "unit")= int 8
##  $ legend.spacing            : 'simpleUnit' num 11points
##   ..- attr(*, "unit")= int 8
##  $ legend.spacing.x          : NULL
##  $ legend.spacing.y          : NULL
##  $ legend.key                : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ legend.key.size           : 'simpleUnit' num 1.2lines
##   ..- attr(*, "unit")= int 3
##  $ legend.key.height         : NULL
##  $ legend.key.width          : NULL
##  $ legend.text               :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : 'rel' num 0.8
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ legend.text.align         : NULL
##  $ legend.title              :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 0
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ legend.title.align        : NULL
##  $ legend.position           : chr "right"
##  $ legend.direction          : NULL
##  $ legend.justification      : chr "center"
##  $ legend.box                : NULL
##  $ legend.box.just           : NULL
##  $ legend.box.margin         : 'margin' num [1:4] 0cm 0cm 0cm 0cm
##   ..- attr(*, "unit")= int 1
##  $ legend.box.background     : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ legend.box.spacing        : 'simpleUnit' num 11points
##   ..- attr(*, "unit")= int 8
##  $ panel.background          : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ panel.border              : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ panel.spacing             : 'simpleUnit' num 5.5points
##   ..- attr(*, "unit")= int 8
##  $ panel.spacing.x           : NULL
##  $ panel.spacing.y           : NULL
##  $ panel.grid                :List of 6
##   ..$ colour       : chr "grey92"
##   ..$ linewidth    : NULL
##   ..$ linetype     : NULL
##   ..$ lineend      : NULL
##   ..$ arrow        : logi FALSE
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_line" "element"
##  $ panel.grid.major          : NULL
##  $ panel.grid.minor          :List of 6
##   ..$ colour       : NULL
##   ..$ linewidth    : 'rel' num 0.5
##   ..$ linetype     : NULL
##   ..$ lineend      : NULL
##   ..$ arrow        : logi FALSE
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_line" "element"
##  $ panel.grid.major.x        : NULL
##  $ panel.grid.major.y        : NULL
##  $ panel.grid.minor.x        : NULL
##  $ panel.grid.minor.y        : NULL
##  $ panel.ontop               : logi FALSE
##  $ plot.background           : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ plot.title                :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : 'rel' num 1.2
##   ..$ hjust        : num 0
##   ..$ vjust        : num 1
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 0points 5.5points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ plot.title.position       : chr "panel"
##  $ plot.subtitle             :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 0
##   ..$ vjust        : num 1
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 0points 5.5points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ plot.caption              :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : 'rel' num 0.8
##   ..$ hjust        : num 1
##   ..$ vjust        : num 1
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 5.5points 0points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ plot.caption.position     : chr "panel"
##  $ plot.tag                  :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : 'rel' num 1.2
##   ..$ hjust        : num 0.5
##   ..$ vjust        : num 0.5
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ plot.tag.position         : chr "topleft"
##  $ plot.margin               : 'margin' num [1:4] 5.5points 5.5points 5.5points 5.5points
##   ..- attr(*, "unit")= int 8
##  $ strip.background          : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ strip.background.x        : NULL
##  $ strip.background.y        : NULL
##  $ strip.clip                : chr "inherit"
##  $ strip.placement           : chr "inside"
##  $ strip.text                :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : chr "grey10"
##   ..$ size         : 'rel' num 0.8
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 4.4points 4.4points 4.4points 4.4points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ strip.text.x              : NULL
##  $ strip.text.x.bottom       : NULL
##  $ strip.text.x.top          : NULL
##  $ strip.text.y              :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : num -90
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ strip.text.y.left         :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : num 90
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ strip.text.y.right        : NULL
##  $ strip.switch.pad.grid     : 'simpleUnit' num 2.75points
##   ..- attr(*, "unit")= int 8
##  $ strip.switch.pad.wrap     : 'simpleUnit' num 2.75points
##   ..- attr(*, "unit")= int 8
##  - attr(*, "class")= chr [1:2] "theme" "gg"
##  - attr(*, "complete")= logi TRUE
##  - attr(*, "validate")= logi TRUE
hrs_indoors_by_cats

>>> According to this analysis, it can be seen on the chart that male house cats spend more time at home on average than female cats and the number of cats in the house does not have a significant effect on the time spent at home.

Question 6: How does the average number of preys of cats vary according to month and gender?

Task 13: Creating a line chart to show the change of mean prey count acc. to month and sex

line_chart_prey_month_colored <- filtered_cats %>%
  group_by(month, animal_sex, .drop = TRUE) %>%
  summarise(mean_prey = mean(prey_p_month, na.rm = TRUE), .groups = "drop") %>%
  ggplot(aes(x = month, y = mean_prey, color = animal_sex)) +
  geom_line() +
  labs(title = "Prey Count per Month (Colored by Animal Sex)",
       x = "Month",
       y = "Mean Prey Count",
       color = "Animal Sex") +
   theme(panel.grid = element_blank(), panel.background = element_rect(fill = "white"), plot.title =  element_text(hjust = 0.5, color = "purple"))
 
line_chart_prey_month_colored

>>> While female cats caught the most prey in October, male cats caught the most prey in June and August. While males caught the least amount of prey in September, females caught it in August.

Extracting a color palette with 10 colors from colorbrewer2.org

color_palette <- brewer.pal(10, "Set3")

Question 7: What is the latitude and longitude distribution of the 10 tag_ids with the highest ground speed?

Finding the 10 tag_ids with the highest ground speed

top_10_ground_speed <- filtered_cats %>%
  group_by(tag_id) %>%
  summarise(mean_speed = mean(ground_speed, na.rm = TRUE)) %>%
  top_n(10, wt = mean_speed)

Filtering these tag_ids

filtered_top_10 <- filtered_cats %>%
  filter(tag_id %in% top_10_ground_speed$tag_id)

Creating scatter plot to show the distribution

scatter_plot_top_10 <- ggplot(filtered_top_10, aes(x = location_long, y = location_lat, color = tag_id)) +
  geom_point() +
  labs(title = "Longitude and Latitude Distribution",
       x = "Longitude",
       y = "Latitude",
       color = "Tag ID") +
  theme(plot.title = element_text(hjust = 0.5, color = "green"))
  scale_color_manual(values = color_palette)
## <ggproto object: Class ScaleDiscrete, Scale, gg>
##     aesthetics: colour
##     axis_order: function
##     break_info: function
##     break_positions: function
##     breaks: waiver
##     call: call
##     clone: function
##     dimension: function
##     drop: TRUE
##     expand: waiver
##     get_breaks: function
##     get_breaks_minor: function
##     get_labels: function
##     get_limits: function
##     guide: legend
##     is_discrete: function
##     is_empty: function
##     labels: waiver
##     limits: NULL
##     make_sec_title: function
##     make_title: function
##     map: function
##     map_df: function
##     n.breaks.cache: NULL
##     na.translate: TRUE
##     na.value: grey50
##     name: waiver
##     palette: function
##     palette.cache: NULL
##     position: left
##     range: environment
##     rescale: function
##     reset: function
##     scale_name: manual
##     train: function
##     train_df: function
##     transform: function
##     transform_df: function
##     super:  <ggproto object: Class ScaleDiscrete, Scale, gg>
scatter_plot_top_10

>>> This analysis shows us that cats with the same tag that leave home do not stray too far from home and mostly spend time in nearby locations.

Question 8: What is the distribution of the number of observations according to age and gender?

Task 15: Faceted Histogram without Legend and with Edge Color

faceted_hist <- ggplot(filtered_cats, aes(x = age_years, fill = animal_sex)) +
  geom_histogram(binwidth = 1, position = "identity", color = "black", alpha = 0.5) +
  labs(title = "Counts of Cats by Age and Sex",
       x = "Age",
       y = "Count") +
  facet_wrap(~animal_sex, scales = "free_y", labeller = labeller(animal_sex = c("f" = "Female", "m" = "Male"))) +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5, color = "blue"), 
        axis.text.y = element_blank(), 
        axis.ticks.y = element_blank(), 
        panel.grid = element_blank(), 
        panel.background = element_rect(fill = 'white'),
        legend.position = "none") +  # removing the legend

  geom_text(
    aes(x = age_years, label = ifelse(..count.. != 0, ..count.., "")),  
    stat = "bin", vjust = -0.5, show.legend = FALSE
  )

faceted_hist
## Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(count)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: Removed 136 rows containing non-finite values (`stat_bin()`).
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 136 rows containing non-finite values (`stat_bin()`).

>>> Observations show that the highest number of female cats is 3 and 9 years old, while the number of 3-year-old cats in males is by far higher than the others. It can easily be said that the total number of male cats is higher.

color_palette <- brewer.pal(8, "Dark2")

Question 9: How do food preferences of house cats vary according to gender?

Food Preference by Sex

violin_plot_food_preference <- ggplot(filtered_cats, aes(x = animal_sex, y = n_cats, fill = ifelse(food_wet, "Wet", "Dry"))) +
  geom_violin() +
  labs(title = "Food Preference by Sex",
       x = "Animal Sex",
       y = "Number of Cats",
       fill = "Food Preference") +
  theme(panel.grid = element_blank(), panel.background = element_rect(fill = 'white'))
  scale_fill_manual(values = color_palette)
## <ggproto object: Class ScaleDiscrete, Scale, gg>
##     aesthetics: fill
##     axis_order: function
##     break_info: function
##     break_positions: function
##     breaks: waiver
##     call: call
##     clone: function
##     dimension: function
##     drop: TRUE
##     expand: waiver
##     get_breaks: function
##     get_breaks_minor: function
##     get_labels: function
##     get_limits: function
##     guide: legend
##     is_discrete: function
##     is_empty: function
##     labels: waiver
##     limits: NULL
##     make_sec_title: function
##     make_title: function
##     map: function
##     map_df: function
##     n.breaks.cache: NULL
##     na.translate: TRUE
##     na.value: grey50
##     name: waiver
##     palette: function
##     palette.cache: NULL
##     position: left
##     range: environment
##     rescale: function
##     reset: function
##     scale_name: manual
##     train: function
##     train_df: function
##     transform: function
##     transform_df: function
##     super:  <ggproto object: Class ScaleDiscrete, Scale, gg>
violin_plot_food_preference

>>> According to the violin plot obtained, it appears that cats of both genders consume wet food more than dry food. In female cats, the highest wet food density appears to be at 2 and 3 years of age, while in males the highest density appears to be at 1 year of age.

10) Question 10: How does the ellipsoid distribution of ground speed and height above vary according to season and being neutered?

Scatter plot with trend line and color-coded food preference

# Defining the color palette
color_palette <- brewer.pal(2, "Set1")
## Warning in brewer.pal(2, "Set1"): minimal value for n is 3, returning requested palette with 3 different levels
# Creating scatter plot with trend line and color-coded (is_neutered)
combined_plot <- ggplot(filtered_cats, aes(x = height_above_ellipsoid, y = ground_speed)) +
  geom_smooth(method = "lm", se = FALSE, linetype = "dashed") +
  labs(title = "Height vs Ground Speed by Season and Being Neutered",
       x = "Height Above Ellipsoid",
       y = "Ground Speed",
       color = "Is Neutered") +
  theme_bw() +
  # Additional layers
  geom_point(aes(color = factor(is_neutered), shape = season), size = 3) +
  guides(color = guide_legend(title = "Is Neutered"),
         shape = guide_legend(title = "Season")) +
  scale_color_manual(values = color_palette) +  
  scale_shape_manual(values = c("Spring" = 16, "Summer" = 17, "Fall" = 18)) 

print(combined_plot)
## `geom_smooth()` using formula = 'y ~ x'

>>> Accordingly, it can be seen that the distribution is concentrated in the ellipsoid region of 0-25000 m/s ground speed and 0-2000 height above. Since there is a non-linear regression, the smoothing method is used to capture the regression. Most of the cats involved in the observations are neutered and most of the observations were taken in the summer.

Conclusion

In this analysis, it was aimed to examine some characteristics and behavioral characteristics of house cats living in England and the following results were obtained:

  1. The average age of house cats is 5 years old.

  2. Neutered cats are faster than non-neutered ones and that adult cats are faster than young one

  3. While house cats hunt mostly in autumn, there are no observations made in winter.

  4. Male house cats spend more time at home on average than female cats and the number of cats in the house does not have a significant effect on the time spent at home.

  5. While female cats caught the most prey in October, male cats caught the most prey in June and August. While males caught the least amount of prey in September, females caught it in August.

  6. Cats with the same tag that leave home do not stray too far from home and mostly spend time in nearby locations.

  7. Cats of both genders consume wet food more than dry food. In female cats, the highest wet food density appears to be at 2 and 3 years of age, while in males the highest density appears to be at 1 year of age.

  8. Distribution is concentrated in the ellipsoid region of 0-25000 m/s ground speed and 0-2000 height above. Since there is a non-linear regression, the smoothing method is used to capture the regression. Most of the cats involved in the observations were neutered and most of the observations were taken in the summer.