plot_hist: plot histogram of data

plot_histR Documentation

plot histogram of data

Description

plot histogram of data

Usage

jj_plot_hist(
  data,
  feature = NULL,
  fill = NULL,
  thres = NULL,
  colour = NULL,
  group = NULL,
  title = "",
  nbins = 50,
  size = 1,
  exclude_zeros = FALSE,
  include_summary = c("n", ">=", "<", ">0<"),
  ...
)

Arguments

feature

vector with values to plot

fill

optional value threshold, for which the number of observations are counted above and below

thres

Value threshold used to fill the histogram. Also used to count the number of observations above and below in include_summary

colour

optional title

group

xlab text

title

colours for bars above and below threshold

nbins

NULL (do not plot numbers) or vector containing any combination of 1 (observations above threshold), 2 (observations below threshold) and 3 (observations below threshold that are not 0)

size

border size for the histogram stacks

exclude_zeros

if TRUE, omit all 0 values from the plot (useful e.g. to plot sparse gene expression)

include_summary

Above the plot, include the number of observations within some ranges. Vector with the possibilties c('n','>=', '<', '>0<'), where n is the total number of observations, >= and < are those above and below the threshold and >0< are those greater than zero, but below the threshold

Examples

df = data.frame(letters = sample(letters[1:4], 100, replace = T),
                groups = paste0('G_', sample(1:2, 100, replace = T)),
                treatment = factor(sample(c('no','yes'), 100, replace = T, prob = c(0.9,0.1)), levels=c('yes','no')),
                values = sample(c(rep(0, 20), rnorm(80, 4, 2))))
jj_plot_hist(df$values)
jj_plot_hist(df, feature = 'values', group = 'groups')
jj_plot_hist(df, feature = 'values', group = 'groups', fill = 'letters', nbins = 30)
jj_plot_hist(df, feature = 'values', colour='treatment', fill = 'letters', title='my title', group = 'groups', size = 1.3, binwidth = 0.4) +
  scale_fill_manual(values = jj_get_jj_colours(df$letters)) + scale_colour_manual(values = c(yes='black', no = "white"))
jj_plot_hist(df, feature = 'values', thres = 4)
jj_plot_hist(df, feature = 'values', thres = 4, exclude_zeros = T, include_summary = c('<', '>='))

mathosi/jj documentation built on Feb. 25, 2024, 2:29 p.m.