Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vertesy opened this issue Oct 18, 2023 · 1 comment
Open

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

vertesy opened this issue Oct 18, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@vertesy
Copy link
Owner

vertesy commented Oct 18, 2023

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.692__H9.sc06.692__H9.bar.pdf"

@vertesy vertesy added the bug Something isn't working label Oct 18, 2023
@vertesy
Copy link
Owner Author

vertesy commented Oct 18, 2023

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant