qhistogram: Draw and save a histogram quickly (via ggplot2).

View source: R/ggExpress.R

qhistogramR Documentation

Draw and save a histogram quickly (via ggplot2).

Description

This all-in-one function draws, annotates, displays and saves a histogram of a distribution provided as a numeric vector. It is a wrapper around ggpubr::ggbarplot(), with the automation of many features. All ggpubr parameters can be accessed through the ... argument.

Usage

qhistogram(
  vec,
  also.pdf = FALSE,
  save.obj = FALSE,
  ext = MarkdownHelpers::ww.set.file.extension(default = "png", also_pdf = also.pdf),
  xlab = FALSE,
  plot = TRUE,
  save = TRUE,
  mdlink = MarkdownHelpers::unless.specified("b.mdlink", def = FALSE),
  plotname = FixPlotName(substitute(vec)),
  subtitle = NULL,
  suffix = NULL,
  caption = suffix,
  filename = NULL,
  logX = FALSE,
  logY = FALSE,
  annotation_logticks_X = logX,
  annotation_logticks_Y = logY,
  vline = FALSE,
  filtercol = 0,
  add = "median",
  palette_use = c("RdBu", "Dark2", "Set2", "jco", "npg", "aaas", "lancet", "ucscgb",
    "uchicago")[4],
  col = as.character(1:3)[1],
  xlab.angle = 90,
  hide.legend = TRUE,
  max.names = 50,
  grid = "y",
  w = 5,
  h = w,
  ...
)

Arguments

vec

A numeric vector for which the histogram is to be plotted.

also.pdf

Save plot in both png and pdf formats.

save.obj

Save the ggplot object to a file. Default: FALSE.

ext

File extension for the saved plot. Either '.pdf' or '.png'. Default is '.pdf'.

xlab

Label for the X-axis. By default, it uses the plot name.

plot

Logical indicating whether to display the plot. Default is TRUE.

save

Logical indicating whether to save the plot into a file. Default is TRUE.

mdlink

Logical indicating whether to insert .pdf and .png image links in the markdown report, set by "path_of_report". Default is FALSE.

plotname

Title of the plot and the name of the file (unless specified in filename). Default is parsed from vec.

subtitle

Optional subtitle text added below the title. Default is NULL.

suffix

Optional suffix added to the filename. Default is NULL.

caption

Optional text added to bottom right corner of the plot. Default = suffix

filename

Optional filename for the saved plot. Default is parsed from plotname.

logX

Logical indicating whether to make X axis on log10 scale. Default is FALSE.

logY

Logical indicating whether to make Y axis on log10 scale. Default is FALSE.

annotation_logticks_X

Logical indicating whether to add annotation logticks on X-axis. Default follows the value of logX.

annotation_logticks_Y

Logical indicating whether to add annotation logticks on Y-axis. Default follows the value of logY.

vline

Numeric value at which to draw a vertical line on the plot. Default is FALSE (no line).

filtercol

Numeric value indicating the direction to color bars above/below the threshold. Default is 0 (no color change).

add

Character defining the type of plot annotations to add. Default is 'median'.

palette_use

Color palette to use from GGpubr. Default is 'jco'.

col

Color of the plot. Default is '1'.

xlab.angle

Angle to rotate X-axis labels. Default is 90 degrees.

hide.legend

Logical indicating whether to hide the legend. Default is TRUE.

max.names

Maximum number of names to show on the axis. Default is 50.

grid

Character indicating the axis to add gridlines. Options are 'x', 'y', or 'xy'. Default is 'y'.

w

Width of the plot. Default is 5.

h

Height of the plot. Default is the same as width.

...

Additional parameters for the corresponding plotting function.

Value

It returns a ggplot object if plot is TRUE.

Examples

## Not run: 
weight <- rnorm(1000)
qhistogram(vec = weight)
qhistogram(vec = weight, vline = 2, filtercol = -1)

## End(Not run)


vertesy/ggExpress documentation built on Nov. 24, 2024, 10:44 p.m.