drawBar: drawBar

View source: R/np_plotting_functions.R

drawBarR Documentation

drawBar

Description

Add a bar plot with options error pars to the active plotting environment

Usage

drawBar(
  x,
  plotColors,
  errorBars = FALSE,
  errorCap = "ball",
  errorLineType = 1,
  width = 0.5,
  sidePlot = FALSE,
  stacked = FALSE,
  capSize = 2,
  lineWidth = 1,
  normalize = FALSE,
  logScale = FALSE,
  logAdjustment = 1
)

Arguments

x

dataframe; Gives top and bottom y-axis positions for the bar plots as well as error bar parameters. See example for details.

plotColors

list; a named list of vectors of colors that set the color options for all NicePlot functions. Names left unspecified will be added and set to default values automatically.

errorBars

Logical; Should error bars be drawn. Defaults to true but is ignored if stack=TRUE.

errorCap

character; Determines the style for the ends of the error bars. Valid options are ball, bar or none.

errorLineType

numeric; Sets lty line type for drawing the error bars.

width

numeric; cex like scaling factor controlling the width of the bars.

sidePlot

logical; Plots bar hight on the x axis if set to TRUE.

stacked

logical; draws a stacked barplot if set to TRUE.

capSize

numeric; cex like scaling value the controls the size of the caps on the error bars.

lineWidth

numeric; Sets the lwd options for controling line plotting thickness for the bar plot.

normalize

logical; Normalizes stacked bars to 100%. If stacked==TRUE and normalize==TRUE the stacked bars will all go to 100%. Otherwise the bars represent the cumuative value.

logScale

numeric; the logarithm base to use for the log scale transformation.

logAdjustment

numeric; a number added to each value prior to log trasformation. Defaults value is 1.

Details

This function draws a series of bars based on a data frame. The expected columns include yt (location top of the bar), yb or bottom of the bar, at indicating where the bar should be drawn, Group which is a unique ID per row, fact which contains an optional stacking factor UpperError for the top of the error bar and LowerError for the location of the bottom of the error bar. The construction of the dataframe is handled automatically from input data by niceBar.

See Also

barplot, niceBar, errorBars

Examples

data(iris)
library(dplyr)
data<-iris  %>% group_by(Species) %>%
    summarize(yt=mean(Sepal.Length),yb=0,UpperError=sd(Sepal.Length),
    LowerError=sd(Sepal.Length)) %>%
    ungroup() %>% select(yt,yb,UpperError,LowerError,Group=Species) %>%
    bind_cols(at=1:3,fact=1:3)
plot(type="n",xlim=c(0,4),ylim=c(0,max(iris$Sepal.Length)),-1,xaxt="n")
# drawBar(data, width=.3, lineWidth=3,plotColors=list(lines="blue",fill="darkgrey"),
# errorBars = T, errorCap = "none")


ZachHunter/NicePlots.R documentation built on Sept. 23, 2023, 4:04 a.m.