Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
abel.vertesy committed Oct 12, 2023
1 parent 3c2cb8d commit f05cc57
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 50 deletions.
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
@@ -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.7.2
version: v0.7.3
message: >-
If you use this software, please cite it using these metadata.
type: software
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ggExpress
Title: ggExpress is the fastest way to create, annotate and export plots
in R
Version: 0.7.2
Version: 0.7.3
Authors@R:
person("Abel", "Vertesy", , "[email protected]", role = c("aut", "cre"))
Author: Abel Vertesy <[email protected]> [aut, cre]
Expand Down Expand Up @@ -38,6 +38,6 @@ Imports:
stats,
tidyverse
Encoding: UTF-8
Packaged: 2023-09-04 18:38:27.811761
Packaged: 2023-10-12 13:21:20.976129
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
2 changes: 1 addition & 1 deletion Development/Create_the_ggExpress_Package.v0.1.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require('Stringendo')

# Setup ------------------------
PackageName = "ggExpress"
package.version = "0.7.2"
package.version = "0.7.3"
setwd("~/GitHub/Packages/")

RepositoryDir = kollapse("~/GitHub/Packages/", PackageName, "/")
Expand Down
66 changes: 41 additions & 25 deletions Development/Development.bac
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
# ____________________________________________________________________



# _________________________________________________________________________________________________
#' @title Quick Histogram Plotting
#'
#' @description This function generates a histogram and saves the plot for a given vector and offers several customizations.
#' @param vec A numeric vector for which the histogram is to be plotted.
#' @param ext File extension for the saved plot. Either '.pdf' or '.png'. Default is '.pdf'.
#' @param also.pdf Save plot in both png and pdf formats
#' @param xlab Label for the X-axis. By default, it uses the plot name.
#' @param plot Logical indicating whether to display the plot. Default is TRUE.
#' @param add Character defining the type of plot annotations to add. Default is 'median'.
Expand Down Expand Up @@ -50,7 +50,8 @@
#'
#' @export
qhistogram <- function(vec
, ext = MarkdownHelpers::unless.specified('b.def.ext', def = 'pdf')
, also.pdf = FALSE
, ext = MarkdownHelpers::ww.set.file.extension(def = 'png')
, xlab = FALSE, plot = TRUE, save = TRUE, mdlink = MarkdownHelpers::unless.specified('b.mdlink', def = FALSE)
, suffix = NULL
, plotname = FixPlotName(substitute(vec), suffix)
Expand Down Expand Up @@ -102,7 +103,7 @@ qhistogram <- function(vec
}
file_name <- FixPlotName(file_name)

if (save) qqSave(ggobj = p, title = plotname, fname = file_name, ext = ext, w = w, h = h)
if (save) qqSave(ggobj = p, title = plotname, fname = file_name, ext = ext, w = w, h = h, also.pdf = also.pdf)
if (mdlink & save) qMarkdownImageLink(file_name)
if (plot) p
}
Expand All @@ -116,6 +117,7 @@ qhistogram <- function(vec
#' @description Draw and save a density plot.
#' @param vec The variable to plot.
#' @param ext File extension (.pdf / .png).
#' @param also.pdf Save plot in both png and pdf formats
#' @param xlab X-axis label.
#' @param plot Display the plot.
#' @param suffix A suffix added to the filename. NULL by default.
Expand All @@ -139,7 +141,8 @@ qhistogram <- function(vec
#' @examples weight <- rnorm(1000); qdensity(weight)

qdensity <- function(vec
, ext = MarkdownHelpers::unless.specified('b.def.ext', def = 'pdf')
, also.pdf = FALSE
, ext = MarkdownHelpers::ww.set.file.extension(def = 'png')
, xlab = FALSE, plot = TRUE
, suffix = NULL
, plotname = FixPlotName(substitute(vec), suffix)
Expand Down Expand Up @@ -172,7 +175,7 @@ qdensity <- function(vec
file_name <- if (!isFALSE(filename)) { filename } else {
FixPlotName(plotname, suffix, "dens", flag.nameiftrue(logX), flag.nameiftrue(logY), ext)
}
if (save) qqSave(ggobj = p, title = plotname, fname = file_name, ext = ext, w = w, h = h)
if (save) qqSave(ggobj = p, title = plotname, fname = file_name, ext = ext, w = w, h = h, also.pdf = also.pdf)
if (mdlink & save) qMarkdownImageLink(file_name)
if (plot) p
}
Expand All @@ -185,6 +188,7 @@ qdensity <- function(vec
#' @description Draw and save a barplot.
#' @param vec The variable to plot.
#' @param ext File extension (.pdf / .png).
#' @param also.pdf Save plot in both png and pdf formats
#' @param plot Display the plot.
#' @param suffix A suffix added to the filename. NULL by default.
#' @param plotname The title of the plot and the name of the file (unless specified in `filename`).
Expand Down Expand Up @@ -216,7 +220,8 @@ qdensity <- function(vec
#' qbarplot(weight3, filtercol = 1, hline = .5)

qbarplot <- function(vec
, ext = MarkdownHelpers::unless.specified('b.def.ext', def = 'pdf')
, also.pdf = FALSE
, ext = MarkdownHelpers::ww.set.file.extension(def = 'png')
, plot = TRUE
, suffix = NULL
, plotname = FixPlotName(substitute(vec), suffix)
Expand Down Expand Up @@ -271,7 +276,7 @@ qbarplot <- function(vec
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)
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
}
Expand All @@ -286,6 +291,7 @@ qbarplot <- function(vec
#' @param fill Color (split) by along Y.
#' @param color Color (split) by along Y.
#' @param ext File extension (.pdf / .png).
#' @param also.pdf Save plot in both png and pdf formats
#' @param plot Display the plot.
#' @param suffix A suffix added to the filename. NULL by default.
#' @param plotname The title of the plot and the name of the file (unless specified in `filename`).
Expand Down Expand Up @@ -321,7 +327,8 @@ qbarplot.df <- function(df
, fill = colnames(df)[3]
, label = NULL
, color = 1
, ext = MarkdownHelpers::unless.specified('b.def.ext', def = 'pdf')
, also.pdf = FALSE
, ext = MarkdownHelpers::ww.set.file.extension(def = 'png')
, plot = TRUE
, suffix = NULL
, plotname = FixPlotName(substitute(df), suffix)
Expand Down Expand Up @@ -362,7 +369,7 @@ qbarplot.df <- function(df
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)
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
}
Expand All @@ -374,6 +381,7 @@ qbarplot.df <- function(df
#' @description Draw and save a pie chart
#' @param vec The variable to plot.
#' @param ext File extension (.pdf / .png).
#' @param also.pdf Save plot in both png and pdf formats
#' @param plot Display the plot.
#' @param save Save the plot into a file.
#' @param mdlink Insert a .pdf and a .png image link in the markdown report, set by "path_of_report".
Expand Down Expand Up @@ -404,7 +412,8 @@ qbarplot.df <- function(df


qpie <- function(vec = MyVec
, ext = MarkdownHelpers::unless.specified('b.def.ext', def = 'pdf')
, also.pdf = FALSE
, ext = MarkdownHelpers::ww.set.file.extension(def = 'png')
, plot = TRUE, save = TRUE, mdlink = MarkdownHelpers::unless.specified('b.mdlink', def = FALSE)
, suffix = NULL
, plotname = FixPlotName(substitute(vec), suffix)
Expand Down Expand Up @@ -484,7 +493,7 @@ qpie <- function(vec = MyVec
file_name <- if (!isFALSE(filename)) filename else {
FixPlotName(plotname, suffix, "pie", ext)
}
if (save) qqSave(ggobj = p, title = plotname, fname = file_name, ext = ext, w = w, h = h)
if (save) qqSave(ggobj = p, title = plotname, fname = file_name, ext = ext, w = w, h = h, also.pdf = also.pdf)
if (mdlink & save) qMarkdownImageLink(file_name)

if (plot) p
Expand All @@ -499,7 +508,7 @@ qpie <- function(vec = MyVec
#' @param plotname The title of the plot and the name of the file (unless specified in `filename`).
#' @param filename Manually provided filename (optional). Default: parse from `plotname`,
#' @param ext File extension (.pdf / .png).
#' @param also.pdf also.pdf
#' @param also.pdf Save plot in both png and pdf formats
#' @param logY Make Y axis log10-scale.
#' @param hline Draw a horizontal line on the plot.
#' @param vline Draw a vertical line on the plot.
Expand Down Expand Up @@ -536,8 +545,8 @@ qboxplot <- function(df_XYcol_or_list
# , fill = c(NULL , 3)[1]
, palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb", "uchicago")[4]
, hide.legend = FALSE
, ext = MarkdownHelpers::unless.specified('b.def.ext', def = 'png')
, also.pdf = TRUE
, ext = MarkdownHelpers::ww.set.file.extension(def = 'png')
, logY = FALSE #, logX = FALSE
, annotation_logticks_Y = logY
, xlab.angle = 90
Expand Down Expand Up @@ -588,7 +597,7 @@ qboxplot <- function(df_XYcol_or_list
#' @param plotname Name of the plot
#' @param filename Manually provided filename (optional). Default: parse from `plotname`,
#' @param ext File extension (.pdf / .png).
#' @param also.pdf also.pdf
#' @param also.pdf Save plot in both png and pdf formats
#' @param logY Make Y axis log10-scale.
#' @param hline Draw a horizontal line on the plot.
#' @param vline Draw a vertical line on the plot.
Expand Down Expand Up @@ -621,8 +630,8 @@ qviolin <- function(df_XYcol_or_list
, stat.method = NULL, stat.label.y.npc = "top", stat.label.x = 0.5
, palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb", "uchicago")[4]
, hide.legend = FALSE
, ext = MarkdownHelpers::unless.specified('b.def.ext', def = 'png')
, also.pdf = FALSE
, ext = MarkdownHelpers::ww.set.file.extension(def = 'png')
, logY = FALSE #, logX = FALSE
, annotation_logticks_Y = logY
, xlab.angle = 45
Expand Down Expand Up @@ -682,7 +691,7 @@ qviolin <- function(df_XYcol_or_list
#' @param filename Manually provided filename (optional). Default: parse from `plotname`,
#' @param plot Display the plot.
#' @param ext File extension (.pdf / .png).
#' @param also.pdf also.pdf
#' @param also.pdf Save plot in both png and pdf formats
#' @param logY Make Y axis log10-scale.
#' @param hline Draw a horizontal line on the plot.
#' @param vline Draw a vertical line on the plot.
Expand Down Expand Up @@ -720,8 +729,8 @@ qstripchart <- function(df_XYcol_or_list
# , fill = c(NULL , 3)[1]
, palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb", "uchicago")[4]
, hide.legend = FALSE
, ext = MarkdownHelpers::unless.specified('b.def.ext', def = 'png')
, also.pdf = TRUE
, ext = MarkdownHelpers::ww.set.file.extension(def = 'png')
, logY = FALSE #, logX = FALSE
, annotation_logticks_Y = logY
, xlab.angle = 90
Expand Down Expand Up @@ -775,7 +784,7 @@ qstripchart <- function(df_XYcol_or_list
#' @param filename Manually provided filename (optional). Default: parse from `plotname`,
#' @param col Color of the plot.
#' @param ext File extension (.pdf / .png).
#' @param also.pdf also.pdf
#' @param also.pdf Save plot in both png and pdf formats
#' @param logX Make X axis log10-scale.
#' @param logY Make Y axis log10-scale.
#' @param hline Draw a horizontal line on the plot, yintercept or FALSE
Expand Down Expand Up @@ -807,8 +816,8 @@ qscatter <- function(df_XYcol
, col = c(NULL , 3)[1]
, palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb", "uchicago")[4]
, hide.legend = FALSE
, ext = MarkdownHelpers::unless.specified('b.def.ext', def = 'png')
, also.pdf = TRUE
, ext = MarkdownHelpers::ww.set.file.extension(def = 'png')
, logX = FALSE, logY = FALSE
, annotation_logticks_Y = logY
, annotation_logticks_X = logX
Expand All @@ -834,8 +843,8 @@ qscatter <- function(df_XYcol


if (grid %in% c("xy", "x", "y")) p <- p + grids(axis = grid)
if (hline) p <- p + ggplot2::geom_hline(yintercept = hline)
if (vline) p <- p + ggplot2::geom_vline(xintercept = vline)
if (sum(hline)) p <- p + ggplot2::geom_hline(yintercept = hline) # sum is needed to deal with multiple lines (multiple values in if statement).
if (sum(vline)) p <- p + ggplot2::geom_vline(xintercept = vline)
if (sum(abline)) p <- p + ggplot2::geom_abline(intercept = abline[1], slope = abline[2])
if (add_contour_plot) p <- p + geom_density_2d()
if (correlation_r2 %in% c("pearson", "spearman") ) p <- p + stat_cor(method = correlation_r2)
Expand Down Expand Up @@ -865,6 +874,7 @@ qscatter <- function(df_XYcol
#' @description Draw and save a Venn Diagram using the `ggVennDiagram` package.
#' @param list The variable to plot.
#' @param ext File extension (.pdf / .png).
#' @param also.pdf Save plot in both png and pdf formats
#' @param plot Display the plot.
#' @param save Save the plot into a file.
#' @param mdlink Insert a .pdf and a .png image link in the markdown report, set by "path_of_report".
Expand All @@ -884,7 +894,8 @@ qscatter <- function(df_XYcol
#' @examples LetterSets <- list("One" = LETTERS[1:7], "Two" = LETTERS[3:12]); qvenn(LetterSets)

qvenn <- function(list
, ext = MarkdownHelpers::unless.specified('b.def.ext', def = 'pdf')
, also.pdf = FALSE
, ext = MarkdownHelpers::ww.set.file.extension(def = 'png')
, plot = TRUE, save = TRUE, mdlink = MarkdownHelpers::unless.specified('b.mdlink', def = FALSE)
, suffix = NULL
, plotname = FixPlotName(substitute(list), suffix)
Expand All @@ -909,7 +920,7 @@ qvenn <- function(list
file_name <- if (!isFALSE(filename)) filename else {
sppp(plotname, suffix, "venn", ext)
}
if (save) qqSave(ggobj = p, title = plotname, fname = file_name, ext = ext, w = w, h = h)
if (save) qqSave(ggobj = p, title = plotname, fname = file_name, ext = ext, w = w, h = h, also.pdf = also.pdf)
if (mdlink & save) qMarkdownImageLink(file_name)
if (plot) p
}
Expand All @@ -931,7 +942,8 @@ qvenn <- function(list
#' @param w width of the plot.
#' @param h height of the plot.
#' @param ext File extension (.pdf / .png).
#' @param also.pdf also.pdf
#' @param also.pdf Save plot in both png and pdf formats
#' @param bgcol Plot background color
#' @param page page
#' @param title title field for pdf file (saved into file metadata)
#' @param fname fname
Expand All @@ -945,6 +957,7 @@ qvenn <- function(list
qqSave <- function(ggobj, w =4, h = w
, ext = MarkdownHelpers::unless.specified('b.def.ext', def = 'png')
, also.pdf = FALSE
, bgcol = 'white'
, page = c(F, "A4p", "A4l", "A5p", "A5l")[1]
, title = FALSE, fname = FALSE
, suffix = NULL, ...) {
Expand All @@ -963,6 +976,9 @@ qqSave <- function(ggobj, w =4, h = w
}
print(paste0(getwd(),"/", fname))

# Set the plot background to white
ggobj <- ggobj + theme(plot.background = element_rect(fill = bgcol, color = bgcol))

if (also.pdf) {
cowplot::save_plot(plot = ggobj, filename = fname2, base_width = w, base_height = h
, title = ww.ttl_field(title, creator = "ggExpress")
Expand Down Expand Up @@ -1069,7 +1085,7 @@ qA4_grid_plot <- function(plot_list
#' @importFrom MarkdownHelpers llogit

qMarkdownImageLink <- function(file_name = 'myplot.pdf') {
llogit(paste0("![", file_name, "]", "(", file_name, ")", collapse = ''))
MarkdownHelpers::llogit(paste0("![", file_name, "]", "(", file_name, ")", collapse = ''))
}


Expand Down
3 changes: 1 addition & 2 deletions R/ggExpress.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# ____________________________________________________________________



# _________________________________________________________________________________________________
#' @title Quick Histogram Plotting
#'
Expand Down Expand Up @@ -1086,7 +1085,7 @@ qA4_grid_plot <- function(plot_list
#' @importFrom MarkdownHelpers llogit

qMarkdownImageLink <- function(file_name = 'myplot.pdf') {
llogit(paste0("![", file_name, "]", "(", file_name, ")", collapse = ''))
MarkdownHelpers::llogit(paste0("![", file_name, "]", "(", file_name, ")", collapse = ''))
}


Expand Down
5 changes: 4 additions & 1 deletion man/qbarplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/qbarplot.df.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f05cc57

Please sign in to comment.