plot.R 1.81 KB
Newer Older
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
1
2
3
4

#' plot_tbl_basic

#' plot_tbl_basic
jml's avatar
jml committed
5
#' @param df tbl_friendlyts data.frame
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
6
#' @param target target
jml's avatar
jml committed
7
#' @param group "none","YEAR","MONTH","WDAY","HOUR","MINUTE","SECOND"
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
8
9
#' @param path path
#' @param name name
jml's avatar
jml committed
10
#' @param DESKTOP boolean
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
11
12
#' @param width_mm width_mm
#' @param height_mm height_mm
Jean-Marie Lepioufle's avatar
typo    
Jean-Marie Lepioufle committed
13
#' @keywords basicr
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
14
15
16
17
18
#' @export
#' @examples
#' \dontrun{
#' plot_tbl_basic()
#' }
jml's avatar
jml committed
19
plot_tbl_basic <- function(df,target,group,path=tempdir(),name=NULL,DESKTOP=TRUE,width_mm=200,height_mm=200){
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
20
21


jml's avatar
jml committed
22
23
  if (!DESKTOP) {
    filename <- normalizePath(file.path(path,paste0("basic_",group,"_",target,".tiff")),mustWork = FALSE)
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
24
25
26
27
28
29
30
31

    grDevices::tiff(filename = filename, width = width_mm, height = height_mm,
          units = "mm", pointsize = 12,
          compression = "lzw",
          bg = "transparent", res = 300)

  } else grDevices::dev.new()

jml's avatar
jml committed
32
  names(df)[names(df)==target] <- "targ"
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
33
  p <- switch(group,
jml's avatar
jml committed
34
35
    "YEAR"    = ggplot2::ggplot(df) + ggplot2::geom_boxplot(ggplot2::aes(x = YEAR, y = targ)) + ggplot2::labs(x = group,  y = target),
    "MONTH"   = ggplot2::ggplot(df) + ggplot2::geom_boxplot(ggplot2::aes(x = MONTH, y = targ)) + ggplot2::labs(x = group,  y = target),
jml's avatar
typo    
jml committed
36
    "WDAY"    = ggplot2::ggplot(df) + ggplot2::geom_boxplot(ggplot2::aes(x = WDAY, y = targ)) + ggplot2::labs(x = group,  y = target),
jml's avatar
jml committed
37
38
39
    "HOUR"    = ggplot2::ggplot(df) + ggplot2::geom_boxplot(ggplot2::aes(x = HOUR, y = targ)) + ggplot2::labs(x = group,  y = target),
    "MINUTE"  = ggplot2::ggplot(df) + ggplot2::geom_boxplot(ggplot2::aes(x = MINUTE, y = targ)) + ggplot2::labs(x = group,  y = target),
    "SECOND"  = ggplot2::ggplot(df) + ggplot2::geom_boxplot(ggplot2::aes(x = SECOND, y = targ)) + ggplot2::labs(x = group,  y = target),
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
40
41
42
43
    stop("group not recognized"))

  print(p)

jml's avatar
jml committed
44
  if (!DESKTOP) {
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
45
    grDevices::dev.off()
jml's avatar
jml committed
46
    print(filename)
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
47
48
49
50
  } else {}

  return(TRUE)
}