gplot: Box-and-Whisker, Violin Plots and Error Bars

View source: R/gplot.R

gplotR Documentation

Box-and-Whisker, Violin Plots and Error Bars

Description

gplot produce box-and-whisker plots, violin plots, and error bars of the given grouped values.

Usage

gplot(formula, data, type = c("boxplot-violin", "boxplot", "violin", "errorbar"), 
  width = c(0.3, 1.0, 0.2), dots = TRUE, binwidth = 0.05, color_manual = NULL, 
  theme = theme_bw(), xlab = NULL, ylab = NULL, title = NULL, 
  option = c("sd", "se"), bar = FALSE, na.rm = TRUE)

Arguments

formula

a formula of the form lhs ~ rhs where lhs gives the sample values and rhs the corresponding groups.

data

a tibble or data frame containing the variables in formula.

type

a character string to select one of the plots. "boxplot-violin": box-and-whisker plot with violin lines, "boxplot": box-and-whisker plot, "violin": violin plot, "errorbar": error bar.

width

a vector including three numeric values. First numeric represents the width of the boxes for box-and-whisker plots (defaults to 0.3). Second numeric belongs to the width of violin plot (defaults to 1.0). Third numeric represents the width of the little lines at the tops and bottoms of the error bars (defaults to 0.20).

dots

a logical to draw the dots corresponding the data values.

binwidth

a numeric to specify bin width of dot(s), defaults to 0.05.

color_manual

a vector of colors. A palette can also be defined with wes_palette. Default is set to "FantasticFox1" available in wes_palette.

theme

a theme (see ggtheme). Default is set to theme_bw().

xlab

a label for the x axis, defaults to a description of x.

ylab

a label for the y axis, defaults to a description of y.

title

a main title for the plot.

option

a character string to select one of the options to draw error bars with standard error or standard deviation. "se": standard error, "sd": standard deviation. Defaults to "sd".

bar

a logical to add bar to errorbars. Default is fixed to bar = FALSE.

na.rm

a logical indicating whether NA values should be stripped before the computation proceeds.

Details

The upper whisker of box-and-whisker plots extends from the hinge to the highest value that is within 1.5 * IQR of the hinge, where IQR is the inter-quartile range. The lower whisker extends from the hinge to the lowest value within 1.5 * IQR of the hinge. Data out of the ends of the whiskers are outliers and plotted as points.

Author(s)

Osman Dag

See Also

geom_boxplot geom_violin

Examples


library(onewaytests)

# box-and-whisker with dots
gplot(Sepal.Length~Species, data = iris, type = "boxplot") 

# box-and-whisker without dots
gplot(Sepal.Length~Species, data = iris, type = "boxplot", dots = FALSE) 

# to change the width of the boxes for box-and-whisker plots
gplot(Sepal.Length~Species, data = iris, type = "boxplot", width = c(0.4, NA, NA)) 

# violin plot with dots
gplot(Sepal.Length~Species, data = iris, type = "violin") 

# to change the width of violin plots
gplot(Sepal.Length~Species, data = iris, type = "violin", width = c(NA, 0.8, NA)) 

# box-and-whisker plot with violin lines and dots
gplot(Sepal.Length~Species, data = iris, type = "boxplot-violin") 

# to change the width of the boxes for box-and-whisker plots and the width of violin plots
gplot(Sepal.Length~Species, data = iris, type = "boxplot-violin", width = c(0.25, 0.95, NA)) 

# to change the theme
library(ggplot2)
gplot(Sepal.Length~Species, data = iris, type = "boxplot-violin", width = c(0.25, 0.95, NA), 
theme = theme_minimal()) 

# to specify the colors 
gplot(Sepal.Length~Species, data = iris, type = "boxplot-violin", width = c(0.25, 0.95, NA), 
color_manual=c("#999999","#E69F00","#56B4E9")) 

# to specify the colors as white
gplot(Sepal.Length~Species, data = iris, type = "boxplot-violin", width = c(0.25, 0.95, NA), 
color_manual=c("white","white","white"))

#to change color palette 
library(wesanderson) 
gplot(Sepal.Length~Species, data = iris, type = "boxplot-violin", width = c(0.25, 0.95, NA), 
color_manual=wes_palette(name="GrandBudapest1",n=3))

# error bars (mean +- standard deviation) without bars
gplot(Sepal.Length~Species, data = iris, type = "errorbar", option = "sd", bar = FALSE) 

# error bars (mean +- standard deviation) with bars
gplot(Sepal.Length~Species, data = iris, type = "errorbar", option = "sd", bar = TRUE) 

# to change the width of the little lines at the tops and bottoms of the error bars
gplot(Sepal.Length~Species, data = iris, type = "errorbar", width = c(NA, NA, 0.25)) 

# error bars (mean +- standard error) without bars
gplot(Sepal.Length~Species, data = iris, type = "errorbar", option = "se", bar = FALSE) 



onewaytests documentation built on Oct. 2, 2023, 1:09 a.m.