R/trends.R

Defines functions trends

Documented in trends

#' @title Create a line graph with trends
#' @description a line plot 
#' @param df a data.frame as input
#' @param x the column for the x axis
#' @param y the value for the y axis (use n if count is generated by the function)
#' @param start start year (numeric)
#' @param end end year (numeric)
#' @param weight The column to use as the weight (e.g. organisation, country etc)
#' @return plot
#' @export
#' @importFrom ggplot2 geom_line
#' @examples \dontrun{trends(lens, x = "publication_year", y = n, start = 1990, end = 2016)}
trends <- function(df, x = NULL, y = NULL, start = NULL, end = NULL, weight = NULL){
  # trends by year (single)
  df %>% 
    group_by(.data[[x]]) %>% 
    count() %>% 
    filter(.data[[x]] >= start && .data[[x]] <= end) %>% 
    ggplot(., aes(.data[[x]], y = n)) + # is y = n really OK here? How to choose y?
    geom_line()

  # facet trends (for example by organisation or keywords or country), show top ten in order?
  
}
poldham/kenlitr documentation built on Nov. 5, 2019, 12:59 a.m.