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

in qbarplot, suffix is added 2x file name if defined #35

Closed vertesy closed 3 weeks ago

vertesy commented 11 months ago

Description in qbarplot(), suffix is added 2x file name, if defined

  qbarplot(Nr.of.UVIs.per.cell, label = Nr.of.UVIs.per.cell, palette_use = "aaas"
           , suffix = NewObj_names[i]
...
)

".../.../Nr.of.UVIs.per.cell.sc06.692H9.sc06.692H9.bar.pdf"

vertesy commented 11 months ago

argument

, plotname = FixPlotName(substitute(vec), suffix)

and

 file_name <- if (!isFALSE(filename)) filename else {
    FixPlotName(plotname, suffix, "bar", flag.nameiftrue(logY), ext)
  }

in Function:

qbarplot <- function(vec
                     , also.pdf = FALSE
                     , ext = MarkdownHelpers::ww.set.file.extension(default = 'pdf', also_pdf = also.pdf)
                     , plot = TRUE
                     , suffix = NULL
                     , plotname = FixPlotName(substitute(vec), suffix)
                     , filename = FALSE
                     , save = TRUE, mdlink = MarkdownHelpers::unless.specified('b.mdlink', def = FALSE)
                     , hline = FALSE, filtercol = 1
                     , palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb", "uchicago")[4]
                     , col = as.character(1:3)[1]
                     , xlab.angle = 45, xlab = ""
                     , logY = FALSE
                     , ylim = c(0, 1.1 * as.numeric(max(vec, na.rm = TRUE)))
                     , annotation_logticks_Y = logY
                     , label = NULL
                     , hide.legend = TRUE
                     , max.names = 50
                     , limitsize = FALSE
                     , grid = 'y'
                     , w = qqqAxisLength(vec), h = 5, ...) {

  stopifnot(is.numeric(vec))
  if (isFALSE(xlab)) xlab = plotname
  df <- qqqNamed.Vec.2.Tbl(namedVec = vec, strip.too.many.names =F)

  if (length(unique(df$"names")) == 1) df$"names" <- as.character(1:length(vec))

  df[["colour"]] <-
    if (length(col) == length(vec)) {
      as.character(col)
    } else if (hline & filtercol != 0) {
      if (filtercol == 1 ) (df$"value" > hline) else if (filtercol == -1 ) (df$"value" < hline)
    } else {
      as.character(rep(col, length(vec))[1:length(vec)])
    }
  print(df)

  p <- ggpubr::ggbarplot(data = df, x = "names", y = "value"
                         , title = plotname, xlab = xlab
                         , color = 'colour', fill = 'colour'
                         , label = label
                         , ylim = ylim
                         , palette = palette_use, ...
  ) + ggpubr::grids(axis = 'y') +
  ggplot2::theme(axis.text.x = ggplot2::element_text(angle = xlab.angle, hjust = 1))
  if (grid %in% c("xy", "x", "y")) p <- p + grids(axis = grid)

  if (length(vec) > max.names) p <- p + ggplot2::guides(x = 'none')
  if (hide.legend) p <- p + ggplot2::theme(legend.position = "none" )

  if (hline) p <- p + ggplot2::geom_hline(yintercept = hline)
  if (logY) p <- p + ggplot2::scale_y_log10()
  if (annotation_logticks_Y) p <- p + annotation_logticks(sides = "l")
  file_name <- if (!isFALSE(filename)) filename else {
    FixPlotName(plotname, suffix, "bar", flag.nameiftrue(logY), ext)
  }
  if (save) qqSave(ggobj = p, title = plotname, fname = file_name, ext = ext, w = w, h = h, limitsize = limitsize, also.pdf = also.pdf)
  if (mdlink & save) qMarkdownImageLink(file_name)
  if (plot) p
}
vertesy commented 3 weeks ago

Was prevalent across funs, but only came up if flag.nameiftrue(xxx) was not null. Nasty.

was FixPlotName(plotname, suffix, "violinplot", flag.nameiftrue(logY), ext)

now FixPlotName(plotname, suffix, flag.nameiftrue(logY), "violinplot", ext)

vertesy commented 3 weeks ago

Resolved in the meanwhile

xxx <- 1:111
qbarplot(xxx, label = xxx, palette_use = "aaas"
         , suffix = "madonna", save = FALSE)