R/wp_plot.R

Defines functions plot.wp_df

Documented in plot.wp_df

#' simple plot function for objects of class wp_df
#' 
#' @method plot wp_df
#' 
#' @param x object of class wp_df to be plotted
#' @param ... other parameter
#' 
#' @export
#' 
#' @import ggplot2 
#' 
plot.wp_df <- function(x, ...){
  
  # make label for data series
  if( length(unique(x$language)) > 1 ){
    x$label <- glue::glue("({x$language}) {x$article}")
  }else{
    x$label <- x$article
  }
  
  # make plot
  ggplot(
    x, 
    mapping = 
      aes_string( 
        x     = "date",
        y     = "views", 
        group = "label", 
        color = "label"
      )
    ) + 
    geom_point() +
    geom_smooth(se = FALSE, method = "loess") + 
    theme_bw()
    
}

Try the wikipediatrend package in your browser

Any scripts or data that you put into this service are public.

wikipediatrend documentation built on July 8, 2020, 5:44 p.m.