diff --git a/CITATION.cff b/CITATION.cff index 86be6cb..e03c9d3 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -1,6 +1,6 @@ cff-version: 1.2.0 title: vertesy/ggExpress - the fastest way to create, annotate and and save plots in R. -version: v0.3.5 +version: v0.3.6 message: >- If you use this software, please cite it using these metadata. type: software diff --git a/DESCRIPTION b/DESCRIPTION index 95c1f0b..d6b42b9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: ggExpress Title: ggExpress is the fastest way to create, annotate and export plots in R -Version: 0.3.5 +Version: 0.3.6 Authors@R: person("Abel", "Vertesy", , "a.vertesy@imba.oeaw.ac.at", role = c("aut", "cre")) Author: Abel Vertesy [aut, cre] @@ -38,6 +38,6 @@ Imports: stats, tidyverse Encoding: UTF-8 -Packaged: 2021-12-14 20:42:20 +Packaged: 2022-01-16 18:56:12 Roxygen: list(markdown = TRUE) RoxygenNote: 7.1.2 diff --git a/Development/Create_the_ggExpress_Package.v0.1.R b/Development/Create_the_ggExpress_Package.v0.1.R index 7d8c0dc..eeddaba 100644 --- a/Development/Create_the_ggExpress_Package.v0.1.R +++ b/Development/Create_the_ggExpress_Package.v0.1.R @@ -19,7 +19,7 @@ require('Stringendo') # Setup ------------------------ PackageName = "ggExpress" -package.version = "0.3.5" +package.version = "0.3.6" setwd("~/GitHub/Packages/") RepositoryDir = kollapse("~/GitHub/Packages/", PackageName, "/") diff --git a/Development/Development.bac b/Development/Development.bac index a52c559..5c43ac0 100644 --- a/Development/Development.bac +++ b/Development/Development.bac @@ -1,8 +1,8 @@ # ____________________________________________________________________ # ggExpress is the fastest way to create, annotate and export plots in R. ---- # ____________________________________________________________________ -# try(source("~/GitHub/Packages/ggExpress/R/ggExpress.functions.R"), silent = T) -# try(source("https://raw.githubusercontent.com/vertesy/ggExpress/main/ggExpress.functions.R"), silent = T) +# try(source("~/GitHub/Packages/ggExpress/R/ggExpress.R"), silent = T) +# try(source("https://raw.githubusercontent.com/vertesy/ggExpress/main/ggExpress.R"), silent = T) # ______________________________________________________________________________________________---- # Main plotting functions ---- @@ -36,7 +36,7 @@ #' @examples weight <- rnorm(1000); qhistogram(vec = weight); qhistogram(vec = weight, vline = 2, filtercol = -1) -qhistogram <- function(vec, ext = "pdf", xlab = F, plot = TRUE, save = TRUE, mdlink = FALSE +qhistogram <- function(vec, ext = "pdf", xlab = F, plot = TRUE, save = TRUE, mdlink = MarkdownHelpers::unless.specified('b.mdlink', def = F) , suffix = NULL , plotname = sppp(substitute(vec), suffix) , logX = F, logY = F @@ -102,7 +102,7 @@ qhistogram <- function(vec, ext = "pdf", xlab = F, plot = TRUE, save = TRUE, mdl qdensity <- function(vec, ext = "pdf", xlab = F, plot = TRUE , suffix = NULL , plotname = sppp(substitute(vec), suffix) - , save = TRUE, mdlink = FALSE + , save = TRUE, mdlink = MarkdownHelpers::unless.specified('b.mdlink', def = F) , logX = F, logY = F , palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb", "uchicago")[4] , max.names = 50 @@ -161,7 +161,7 @@ qbarplot <- function(vec, ext = "pdf", plot = TRUE , suffix = NULL , plotname = sppp(substitute(vec), suffix) # , title = F - , save = TRUE, mdlink = FALSE + , save = TRUE, mdlink = MarkdownHelpers::unless.specified('b.mdlink', def = F) , hline = F, filtercol = 1 , palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb", "uchicago")[4] , col = as.character(1:3)[1] @@ -175,17 +175,19 @@ qbarplot <- function(vec, ext = "pdf", plot = TRUE if (isFALSE(xlab)) xlab = plotname - df <- qqqCovert.named.vec2tbl(namedVec = vec, thr = max.names) + df <- qqqCovert.named.vec2tbl(namedVec = vec, strip.too.many.names =F) # nrCategories.DFcol1 <- length(unique(df[,1])); stopif( nrCategories.DFcol1 >100) if (length(unique(df$"names")) == 1) df$"names" <- as.character(1:length(vec)) - df[["colour"]] <- if (hline & filtercol != 0) { - if (filtercol == 1 ) (df$"value" > hline) else if (filtercol == -1 ) (df$"value" < hline) - } else if (length(col) == length(vec)) { - as.character(col) - } else { - as.character(rep(col, length(vec))[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" @@ -195,6 +197,7 @@ qbarplot <- function(vec, ext = "pdf", plot = TRUE , palette = palette_use, ... ) + ggpubr::grids(axis = 'y') + if (length(vec) > max.names) p <- p + ggplot2::guides(x = 'none') if (hide.legend) { p <- p + ggplot2::theme(legend.position = "none" , axis.text.x = ggplot2::element_text(angle = xlab.angle, hjust = 1) ) } @@ -238,7 +241,7 @@ qbarplot <- function(vec, ext = "pdf", plot = TRUE #' @examples xvec <- c("A"=12, "B"=29); qpie(vec = xvec) qpie <- function(vec = Network.Size - , ext = "pdf", plot = TRUE, save = TRUE, mdlink = FALSE + , ext = "pdf", plot = TRUE, save = TRUE, mdlink = MarkdownHelpers::unless.specified('b.mdlink', def = F) , suffix = NULL , plotname = sppp(substitute(vec), suffix) , LegendSide = TRUE @@ -247,8 +250,9 @@ qpie <- function(vec = Network.Size , custom.order = FALSE , extended.canvas = TRUE , palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb", "uchicago")[4] + , custom.margin = T , max.categories = 100 - , max.names = 5 + , max.names = 10 , decr.order = TRUE , both_pc_and_value = TRUE , w = 5, h = w, ...) { @@ -273,7 +277,7 @@ qpie <- function(vec = Network.Size if (is.null(names(vec))) { names(vec) <- as.character(1:length(vec)) } - df <- qqqCovert.named.vec2tbl.v2(namedVec = vec, thr = max.names) + df <- qqqCovert.named.vec2tbl(namedVec = vec, thr = max.names) if (l.orig > max.categories) df[['names']][length(df$'names')] <- name.of.last pcX <- df$"value" / sum(df$"value") @@ -363,7 +367,7 @@ qboxplot <- function(df_XYcol , palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb", "uchicago")[4] , ext = "png", also.pdf = T , logY = F #, logX = F - , hline = F, vline = F, plot = TRUE, save = TRUE, mdlink = FALSE + , hline = F, vline = F, plot = TRUE, save = TRUE, mdlink = MarkdownHelpers::unless.specified('b.mdlink', def = F) , w = 7, h = w, ...) { # plotname <- if (isFALSE(title)) Stringendo::kpp(make.names(as.character(substitute(df_XYcol))), suffix) else title vars <- colnames(df_XYcol) @@ -433,7 +437,7 @@ qviolin <- function(df_XYcol , palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb", "uchicago")[4] , ext = "png", also.pdf = T , logY = F #, logX = F - , hline = F, vline = F, plot = TRUE, save = TRUE, mdlink = FALSE + , hline = F, vline = F, plot = TRUE, save = TRUE, mdlink = MarkdownHelpers::unless.specified('b.mdlink', def = F) , w = 7, h = w, ...) { # plotname <- if (isFALSE(title)) Stringendo::kpp(make.names(as.character(substitute(df_XYcol))), suffix) else title vars <- colnames(df_XYcol) @@ -493,7 +497,7 @@ qscatter <- function(df_XYcol , palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb", "uchicago")[4] , ext = "png", also.pdf = T , logX = F, logY = F - , hline = F, vline = F, plot = TRUE, save = TRUE, mdlink = FALSE + , hline = F, vline = F, plot = TRUE, save = TRUE, mdlink = MarkdownHelpers::unless.specified('b.mdlink', def = F) , w = 7, h = w, ...) { # plotname <- if (isFALSE(title)) Stringendo::kpp(make.names(as.character(substitute(df_XYcol))), suffix) else title vars <- colnames(df_XYcol) @@ -608,13 +612,14 @@ qqqCovert.named.vec2tbl <- function(namedVec=1:14, verbose = F, strip.too.many.n # Check naming issues nr.uniq.names <- length(unique(names(namedVec))) - if (nr.uniq.names > thr & verbose) print("Vector has", thr, "+ names. Can mess up auto-color legends.") + if (nr.uniq.names > thr & verbose) iprint("Vector has", thr, "+ names. Can mess up auto-color legends.") if (nr.uniq.names < 1 & verbose) print("Vector has no names") an.issue.w.names <- (nr.uniq.names > thr | nr.uniq.names < 1 ) idx.elements.above.thr <- if (thr < length(namedVec)) thr:length(namedVec) else 1:length(namedVec) if (strip.too.many.names & an.issue.w.names) names(namedVec)[idx.elements.above.thr] <- rep("", length(idx.elements.above.thr)) - if (length(unique(names(namedVec))) > thr) print("Vector has", thr, "+ names. Can mess up auto-color legends.") + + if (length(unique(names(namedVec))) > thr) iprint("Vector has", thr, "+ names. Can mess up auto-color legends.") df <- tibble::as_tibble(cbind("value" = namedVec)) nm <- names(namedVec) diff --git a/man/qbarplot.Rd b/man/qbarplot.Rd index e44e14d..16444ec 100644 --- a/man/qbarplot.Rd +++ b/man/qbarplot.Rd @@ -11,7 +11,7 @@ qbarplot( suffix = NULL, plotname = sppp(substitute(vec), suffix), save = TRUE, - mdlink = FALSE, + mdlink = MarkdownHelpers::unless.specified("b.mdlink", def = F), hline = F, filtercol = 1, palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb", diff --git a/man/qboxplot.Rd b/man/qboxplot.Rd index e4125d4..d6f00b6 100644 --- a/man/qboxplot.Rd +++ b/man/qboxplot.Rd @@ -23,7 +23,7 @@ qboxplot( vline = F, plot = TRUE, save = TRUE, - mdlink = FALSE, + mdlink = MarkdownHelpers::unless.specified("b.mdlink", def = F), w = 7, h = w, ... diff --git a/man/qdensity.Rd b/man/qdensity.Rd index ca9b4ab..1939af7 100644 --- a/man/qdensity.Rd +++ b/man/qdensity.Rd @@ -12,7 +12,7 @@ qdensity( suffix = NULL, plotname = sppp(substitute(vec), suffix), save = TRUE, - mdlink = FALSE, + mdlink = MarkdownHelpers::unless.specified("b.mdlink", def = F), logX = F, logY = F, palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb", diff --git a/man/qhistogram.Rd b/man/qhistogram.Rd index 6d4d744..36222f7 100644 --- a/man/qhistogram.Rd +++ b/man/qhistogram.Rd @@ -10,7 +10,7 @@ qhistogram( xlab = F, plot = TRUE, save = TRUE, - mdlink = FALSE, + mdlink = MarkdownHelpers::unless.specified("b.mdlink", def = F), suffix = NULL, plotname = sppp(substitute(vec), suffix), logX = F, diff --git a/man/qpie.Rd b/man/qpie.Rd index fe08f76..e751c74 100644 --- a/man/qpie.Rd +++ b/man/qpie.Rd @@ -9,7 +9,7 @@ qpie( ext = "pdf", plot = TRUE, save = TRUE, - mdlink = FALSE, + mdlink = MarkdownHelpers::unless.specified("b.mdlink", def = F), suffix = NULL, plotname = sppp(substitute(vec), suffix), LegendSide = TRUE, @@ -21,8 +21,9 @@ qpie( extended.canvas = TRUE, palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb", "uchicago")[4], + custom.margin = T, max.categories = 100, - max.names = 5, + max.names = 10, decr.order = TRUE, both_pc_and_value = TRUE, w = 5, diff --git a/man/qscatter.Rd b/man/qscatter.Rd index 4bf39ba..147b56a 100644 --- a/man/qscatter.Rd +++ b/man/qscatter.Rd @@ -19,7 +19,7 @@ qscatter( vline = F, plot = TRUE, save = TRUE, - mdlink = FALSE, + mdlink = MarkdownHelpers::unless.specified("b.mdlink", def = F), w = 7, h = w, ... diff --git a/man/qviolin.Rd b/man/qviolin.Rd index dc58a2e..a95dbf7 100644 --- a/man/qviolin.Rd +++ b/man/qviolin.Rd @@ -22,7 +22,7 @@ qviolin( vline = F, plot = TRUE, save = TRUE, - mdlink = FALSE, + mdlink = MarkdownHelpers::unless.specified("b.mdlink", def = F), w = 7, h = w, ...