qbarplot.df: qbarplot.df - Barplot for tibbles or dataframes

View source: R/ggExpress.R

qbarplot.dfR Documentation

qbarplot.df - Barplot for tibbles or dataframes

Description

Draw and save a barplot for tibbles or dataframes

Usage

qbarplot.df(
  df,
  x = colnames(df)[1],
  y = colnames(df)[2],
  fill = colnames(df)[3],
  color = 1,
  label = NULL,
  also.pdf = FALSE,
  save.obj = FALSE,
  ext = MarkdownHelpers::ww.set.file.extension(default = "png", also_pdf = also.pdf),
  plotname = FixPlotName(substitute(df)),
  subtitle = NULL,
  suffix = NULL,
  caption = suffix,
  filename = NULL,
  scale = TRUE,
  plot = TRUE,
  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],
  xlab.angle = 45,
  xlab = NULL,
  logY = FALSE,
  annotation_logticks_Y = logY,
  hide.legend = TRUE,
  max.names = 50,
  limitsize = FALSE,
  grid = "y",
  max.categ = 10,
  w = qqqAxisLength(df),
  h = 5,
  ...
)

Arguments

df

The variable to plot.

x

Colname to split along X axis. Default: colnames(df)[1].

y

Colname to count along y axis. Default: colnames(df)[2].

fill

Color (split) by along Y. Default: colnames(df)[3].

color

Color (split) by along Y.

label

label

also.pdf

Save plot in both png and pdf formats.

save.obj

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

ext

File extension (.pdf / .png).

plotname

The title of the plot and the name of the file (unless specified in filename).

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

Manually provided filename (optional). Default: parse from plotname,

scale

Scale the Y axis to 100%.

plot

Display the plot.

save

Save the plot into a file.

mdlink

Insert a .pdf and a .png image link in the markdown report, set by "path_of_report".

hline

Draw a horizontal line on the plot.

filtercol

Color bars below / above the threshold with red / green. Define the direction by -1 or 1. Takes effect if "*line" is defined.

palette_use

GGpubr Color palette to use.

xlab.angle

Rotate X-axis labels by N degree. Default: 90

xlab

X-axis label. Default: NULL.

logY

Make Y axis log10-scale.

annotation_logticks_Y

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

hide.legend

hide legend

max.names

The maximum number of names still to be shown on the axis.

limitsize

limitsize

grid

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

max.categ

Maximum number of categories to show on the plot. Default is 10.

w

Width of the plot.

h

Height of the plot.

...

Pass any other parameter of the corresponding plotting function(most of them should work).

Examples

my_tibble <- tibble(
  Column_1 = c("A", "A", "A", "B", "C", "C"),
  Column_2 = c("X", "Y", "Y", "Z", "X", "Z")
)
freq_table <- my_tibble |> count(Column_1, Column_2)
qbarplot.df(freq_table)


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