R/peru_point.R

#' Draw PERU scatterplot.
#' 
#' @param data
#' @param x,y
#' @param vcolor - color variable. Default value: NULL
#' @param ... - all parameters from geom_point and theme_peru
#' @examples 
#' \dontrun{
#' peru_point(mtcars, mpg, wt)
#' peru_point(mtcars, mpg, wt, factor(cyl),color = categorical_colors)
#' peru_point(mtcars, mpg, wt, factor(cyl),color = categorical_colors[c(5,6,7)])
#' }
# 
# peru_point <- function(data, x, y, vcolor = NULL, ...) {
#   # get what geom_point accepts
#   geom_point_aes <- c("x", "y", "alpha", "colour", "color", "fill", "shape", "size", "stroke")
#   point_params <- unique(c(geom_point_aes, 
#                            names(formals(geom_point)), 
#                            names(formals(layer))))
#   
#   # get what scale_y_continuous accepts
#   theme_peru_params <- unique(names(formals(theme_peru)))
#   
#   if (!(missing(vcolor))){
#     gg <- ggplot(data = data, aes_(substitute(x), substitute(y), color = substitute(vcolor)))
#     base_args <- list(size = 6, method = 'color')
#     point_params <- point_params[!grepl('colo',point_params)]
#   }
#   else {
#     gg <- ggplot(data = data, aes_(substitute(x), substitute(y)))
#     base_args <- list(size = 6, color = categorical_colors[1])
#   }
#   
#   args <- list(...)
#   args <- c(args, base_args)
#   
#   # get all the arg names
#   arg_names <- unique(names(args))
#   
#   gg <- gg + do.call(geom_point, 
#                      sapply(intersect(arg_names, point_params), 
#                             function(x) { list(args[[x]]) }))
#   
#   # which ones are left for theme_peru
#   gg <- gg + do.call(theme_peru, 
#                      sapply(intersect(arg_names, theme_peru_params), 
#                             function(x) { list(args[[x]]) }))
#   
#   gg <- gg + 
#     guides(colour = guide_legend(override.aes = list(size = 10)))
#   
#   return(gg)
# }
AMUFacultyOfEnglish/ENRanalytics documentation built on May 5, 2019, 11:36 a.m.