Learn R Programming

DescTools (version 0.99.7)

AddConnLines: Add Connection Lines to a Barplot

Description

Add connection lines to a stacked barplot (beside = TRUE is not supported). The function expects exactly the same arguments, that were used to create the barplot.

Usage

AddConnLines(..., lcol = 1, lwd = 1, lty = "solid")

Arguments

...
the arguments used to create the barplot. (The dots are sent directly to barplot).
lcol
the line color of the connection lines. Defaults to black.
lwd
the line width for the connection lines. Default is 1.
lty
the line type for the connection lines. Line types can either be specified as an integer (0=blank, 1=solid (default), 2=dashed, 3=dotted, 4=dotdash, 5=longdash, 6=twodash) or as one of the character strings "blank", "solid"

See Also

barplot

Examples

Run this code
tab <- with( 
  subset(d.pizza, driver %in% c("Carpenter","Miller","Farmer","Butcher")), 
  table(factor(driver), Weekday(date, "a", stringsAsFactor=TRUE))
)
tab

barplot(tab, beside=FALSE, space=1.2) 
AddConnLines(tab, beside=FALSE, space=1.2, lcol="grey50", lwd=1, lty=2) 

barplot(tab, beside=FALSE, space=1.2, horiz=TRUE) 
AddConnLines(tab, beside=FALSE, space=1.2, horiz=TRUE, lcol="grey50", lwd=1, lty=2)


cols <- PalHelsana()[1:4]
b <- barplot(tab, beside=FALSE, horiz=FALSE, col=cols) 
AddConnLines(tab, beside=FALSE, horiz=FALSE, lcol="grey50", lwd=1, lty=2) 

# set some labels
text(x=b, y=t(apply(rbind(0,tab), 2, Midx)), labels=tab, 
     col=(matrix(rep(TextContrastColor(cols), each=ncol(tab)), nrow=nrow(tab), byrow=FALSE )))

Run the code above in your browser using DataLab