View source: R/np_plotting_functions.R
drawBar | R Documentation |
Add a bar plot with options error pars to the active plotting environment
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
)
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 |
errorCap |
character; Determines the style for the ends of the error bars. Valid options are |
errorLineType |
numeric; Sets |
width |
numeric; cex like scaling factor controlling the width of the bars. |
sidePlot |
logical; Plots bar hight on the x axis if set to |
stacked |
logical; draws a stacked barplot if set to |
capSize |
numeric; cex like scaling value the controls the size of the caps on the error bars. |
lineWidth |
numeric; Sets the |
normalize |
logical; Normalizes stacked bars to 100%. If |
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. |
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
.
barplot
, niceBar
, errorBars
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.