vertesy / ggExpress

ggExpress is the fastest way to create, annotate and and save plots in R.
https://vertesy.github.io/ggExpress
GNU General Public License v3.0
4 stars 2 forks source link

qqqParsePlotname() does not substitute #22

Closed vertesy closed 2 years ago

vertesy commented 2 years ago

Expected Behavior Name parsed from variable name e.g abc

Buggy Behavior Name is the name of the param = vec


qqqParsePlotname <- function(string = "sadsad", suffix_tag= NULL) { # parse plot name from variable name and suffix
  nm <- make.names((substitute(string)))
  if (!is.null(suffix_tag) & !isFALSE(suffix_tag)) nm <- Stringendo::kpp(nm, suffix_tag)
  print(11)
  print(nm)

  return(nm)
}

qpie <- function(vec, ext = "pdf", plot = TRUE, save = TRUE, mdlink = FALSE
                 , suffix = NULL
                 , plotname = FixPath() kpp(substitute(vec), suffix)
                 , LegendSide = T, LegendTitle = as.character(substitute(vec)), NoLegend = F
                 , pcdigits = 2, NamedSlices =F
                 , custom.order = F
                 # , custom.margin = F
                 , palette_use = 'jco'
                 , max.names = 50
                 , w = 5, h = w, ...) {

  df <- qqqCovert.named.vec2tbl(namedVec = vec, thr = max.names)
  nrCategories.DFcol1 <- length(unique(df[,1])); stopif( nrCategories.DFcol1 > 100)

  pcX <- df$"value" / sum(df$"value")
  labs <- paste(100 * signif (pcX, pcdigits), "%", sep = "")
  if (NamedSlices) labs <- paste(df$names, "\n", labs)
  print(df)
  if (custom.order != F) df$'names' <- factor(df$'names', levels = custom.order)

  p <- ggpubr::ggpie(data = df, x = "value", label = labs
                     , fill = "names", color = "white"
                     , title = plotname
                     , palette = palette_use, ...)
  if (LegendSide) p <- ggpubr::ggpar(p, legend = "right", legend.title = LegendTitle)
  # if (custom.margin) p <- p + theme(plot.margin = unit(custom.margin, "cm"))
  # p <- if (NoLegend) p + NoLegend() else p
  p <- if (NoLegend) p + theme(legend.position = "none", validate = TRUE) else p
  fname = Stringendo::kpp(plotname, suffix, "pie",  ext)
  if (save) qqSave(ggobj = p, title = plotname, fname = fname, ext = ext, w = w, h = h)
  if (mdlink & save) qMarkdownImageLink(fname)
  if (plot) p
}

abc <- 1:3
qpie(abc)

image