Code
library(tidyverse)
::opts_chunk$set(echo = TRUE)
knitrinstall.packages(summarytools)
Error in install.packages(summarytools): object 'summarytools' not found
Code
library(summarytools)
Michele Carlin
February 17, 2023
Rows: 30977 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (8): Domain Code, Domain, Area, Element, Item, Unit, Flag, Flag Description
dbl (6): Area Code, Element Code, Item Code, Year Code, Year, Value
ℹ 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.
spc_tbl_ [30,977 × 14] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
$ Domain Code : chr [1:30977] "QA" "QA" "QA" "QA" ...
$ Domain : chr [1:30977] "Live Animals" "Live Animals" "Live Animals" "Live Animals" ...
$ Area Code : num [1:30977] 2 2 2 2 2 2 2 2 2 2 ...
$ Area : chr [1:30977] "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
$ Element Code : num [1:30977] 5112 5112 5112 5112 5112 ...
$ Element : chr [1:30977] "Stocks" "Stocks" "Stocks" "Stocks" ...
$ Item Code : num [1:30977] 1057 1057 1057 1057 1057 ...
$ Item : chr [1:30977] "Chickens" "Chickens" "Chickens" "Chickens" ...
$ Year Code : num [1:30977] 1961 1962 1963 1964 1965 ...
$ Year : num [1:30977] 1961 1962 1963 1964 1965 ...
$ Unit : chr [1:30977] "1000 Head" "1000 Head" "1000 Head" "1000 Head" ...
$ Value : num [1:30977] 4700 4900 5000 5300 5500 5800 6600 6290 6300 6000 ...
$ Flag : chr [1:30977] "F" "F" "F" "F" ...
$ Flag Description: chr [1:30977] "FAO estimate" "FAO estimate" "FAO estimate" "FAO estimate" ...
- attr(*, "spec")=
.. cols(
.. `Domain Code` = col_character(),
.. Domain = col_character(),
.. `Area Code` = col_double(),
.. Area = col_character(),
.. `Element Code` = col_double(),
.. Element = col_character(),
.. `Item Code` = col_double(),
.. Item = col_character(),
.. `Year Code` = col_double(),
.. Year = col_double(),
.. Unit = col_character(),
.. Value = col_double(),
.. Flag = col_character(),
.. `Flag Description` = col_character()
.. )
- attr(*, "problems")=<externalptr>
Decade
1960s 1970s 1980s 1990s 2000s 2010s
4449 4982 4988 5613 5754 5191
---
title: "International Data on Bird Counts from 1960s-2010s"
author: "Michele Carlin"
desription: "Summarized data by decade"
date: "02/17/2023"
format:
html:
toc: true
code-fold: true
code-copy: true
code-tools: true
categories:
- challenge_1
- Michele Carlin
- birds.csv
---
## Install packages
```{r}
#| label: setup
#| warning: false
library(tidyverse)
knitr::opts_chunk$set(echo = TRUE)
install.packages(summarytools)
library(summarytools)
```
## Read in and view 'birds' dataset
```{r}
library(readr)
birds <- read_csv ("C:/Users/CarlinML/DACSS-601/601_Spring_2023/posts/_data/birds.csv")
View(birds)
```
## List of variables in dataset
```{r}
str(birds)
```
## dfSummary
```{r}
view(dfSummary(birds))
```
## Number of unique values in the variable 'Item'
```{r}
birds%>%
select(Item)%>%
n_distinct(.)
```
## Frequency table of 'Item'
```{r}
table(select(birds, Item))
```
## This dataset contains data on the number of bird 'units' by country from the 1960's to the 2010's. Data is available for various types of birds (e.g., chickens, ducks, turkeys, etc.).
## Recoded 'Year' variable into 'Decade' variable
```{r}
birds<-birds%>%
mutate(Decade = case_when(
Year >= 1960 & Year < 1970 ~ "1960s",
Year >= 1970 & Year < 1980 ~ "1970s",
Year >= 1980 & Year < 1990 ~ "1980s",
Year >= 1990 & Year < 2000 ~ "1990s",
Year >= 2000 & Year < 2010 ~ "2000s",
Year >= 2010 ~ "2010s")
)
table(select(birds, Decade))
```
## Created crosstabs of Item by Decade
```{r}
xtabs(~ Decade + Item, birds)
```
## Created graphic display of Bird Type by Decade
```{r}
ggplot(birds, aes(x=Item, y=Value)) +
geom_col()+
facet_wrap(vars(Decade), scales = "free_x") +
labs(title = "International Bird Counts by Decade", y = "Number", x = "Type of Bird")
```