challenge_9
Creating a function
Author

Daniel Manning

Published

January 28, 2023

Code
library(tidyverse)
library(ggplot2)
library(here)

knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)

Create a function

Code
plot_hist <-function(d, x){
  ggplot(d, aes(x=x)) + geom_histogram() +
  geom_histogram(binwidth=1000)
}

Load Dataset

Code
egg <- here("posts","_data","FAOSTAT_egg_chicken.csv")%>%
  read_csv()
egg
# A tibble: 38,170 × 14
   `Domain Code` Domain     `Area Code` Area  `Element Code` Element `Item Code`
   <chr>         <chr>            <dbl> <chr>          <dbl> <chr>         <dbl>
 1 QL            Livestock…           2 Afgh…           5313 Laying         1062
 2 QL            Livestock…           2 Afgh…           5410 Yield          1062
 3 QL            Livestock…           2 Afgh…           5510 Produc…        1062
 4 QL            Livestock…           2 Afgh…           5313 Laying         1062
 5 QL            Livestock…           2 Afgh…           5410 Yield          1062
 6 QL            Livestock…           2 Afgh…           5510 Produc…        1062
 7 QL            Livestock…           2 Afgh…           5313 Laying         1062
 8 QL            Livestock…           2 Afgh…           5410 Yield          1062
 9 QL            Livestock…           2 Afgh…           5510 Produc…        1062
10 QL            Livestock…           2 Afgh…           5313 Laying         1062
# … with 38,160 more rows, and 7 more variables: Item <chr>, `Year Code` <dbl>,
#   Year <dbl>, Unit <chr>, Value <dbl>, Flag <chr>, `Flag Description` <chr>

Test function

Code
plot_hist(egg, egg$Value)