R/draw_a_name.R

Defines functions draw_a_name

Documented in draw_a_name

#' draw_a_name
#'
#' @param the_name name
#' @param the_sex sex of the person
#'
#' @import prenoms tidyr ggplot2 assertthat
#' @importFrom dplyr group_by
#' @return result
#' @examples
#' draw_a_name("Marie","F")
#'
#' @export
#'
#'
draw_a_name <- function(the_name,the_sex){
  assert_that(is.character(the_name))
  assert_that( the_name %in% prenoms::prenoms$name)
  assert_that(is.character(the_sex))
  assert_that( the_sex %in% c("M", "F"))
  prenom_year <- prenoms::prenoms %>%
    filter(name == the_name, sex == the_sex) %>%
    group_by(year) %>%
    summarise(n=sum(n))

  result <- ggplot(data = prenom_year,
                   aes(x = year, y = n )) +
    geom_line() +
    ggtitle(the_name) +
    xlab("Years")

  return(result)
}
mathildelavacquery/mlpackage documentation built on Nov. 18, 2017, 5:14 p.m.