general.bar_plot_by: Function to create a barplot, with bars split by a second...

Description Usage Arguments Value Author(s) Examples

Description

Function to create a barplot, with bars split by a second variable

Usage

1
2
3
4
5
general.bar_plot_by(freq, labels = NULL, labels.ab = NULL, file.name,
  col = "tomato3", cex.lab = 1, cex.lab.ab = 1, cex.x = 1, xlab = "",
  ylab = "Frequency", add.legend = FALSE, leg.lab = NULL,
  leg.col = NULL, leg.title = NULL, mar = c(5, 4, 3, 1), png.width = 6,
  png.height = 5, png.out = TRUE)

Arguments

freq

vector or matrix with the bar heights, e.g. a frequency table ('table()' output), names will be used for bar labels if 'labels' is not specified, if 'freq' is a matrix, entries of each column are represented by separate bars with no space in between

labels

bar labels (default=NULL)

labels.ab

additional labels, which are placed above the bars (default=NULL), should have the same dimension as 'freq'

file.name

name for the PNG output file (without '.png' ending)

col

color for the bars (default='tomato3'). can be a single value or an object of the same dimension than freq, specifying the color for each bar

cex.lab

size of the bar labels (default=1)

cex.lab.ab

size of the bar labels above the bars (default=1)

cex.x

size of the x-labels (default=1)

xlab

label for the x-axis (default=”)

ylab

label for the y-axis (default='Frequency')

add.legend

TRUE/FALSE should a legend be added underneath the plot (default=TRUE), only works if legend parameters are specified

leg.lab

labels for the legend (default=NULL)

leg.col

colors for the legend (default=NULL)

leg.title

title for the legend (default=NULL)

mar

plot margin (default=c(5,4,3,1))

png.width

width of the PNG-file in inches (default=6)

png.height

height of the PNG-file in inches (default=5)

png.out

TRUE/FALSE if true, a png file is created as output, otherwise the plot is created in the R graphic device

Value

PNG file with the barplot ('file.name.png') numeric vector with size of the PNG-file in inches for rescaling in RTF

Author(s)

Sebastian Voss, Adam Skubala

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
## Not run: 
set.seed(42)
x <- sample(1:15, size=500, replace=TRUE)
by <- sample(c('A','B'), size=500, replace=TRUE)
freq <- table(by, x)
col <- matrix(ncol=ncol(freq), nrow=nrow(freq))

col1 <- colorRampPalette(c('tomato3','grey95'))
col[1,] <- col1(9)[1]
col[2,] <- col1(9)[7]

col2 <- colorRampPalette(c('skyblue2','grey95'))
col[1,c(5,11)] <- col2(9)[1]
col[2,c(5,11)] <- col2(9)[7]

cex.lab <- 0.7
cex.lab.ab <- 0.5
cex.x <- 0.9
labels <- NULL
labels.ab <- rep(paste0('X', 1:15), each=2)
labels.ab[which(1:length(labels.ab) %% 2 == 0)] <- ''
mar <- c(7,4,3,1)
xlab <- 'numbers'
ylab <- 'frequencies'
file.name <- 'test'
png.width <- 7
png.height <- 6
add.legend <- TRUE
leg.title <- 'color'
leg.col <- c(col1(9)[1],col1(9)[7],col2(9)[1],col2(9)[7])
leg.lab <- c('red','faded red','blue','faded blue')

general.bar_plot_by(freq=freq, labels=NULL, labels.ab=labels.ab, 
    file.name='test1_barplot', col=col, cex.lab=0.7, cex.lab.ab=0.5, cex.x=0.8,
      xlab='Number', ylab='Frequency', add.legend=TRUE, 
      leg.lab=leg.lab, leg.col=leg.col, leg.title='color',
      mar=c(7,4,3,1), png.width=7, png.height=6)
general.bar_plot_by(freq=freq, labels=paste0('X', 1:15), labels.ab=NULL, 
    file.name='test2_barplot', 
    col=col, cex.lab=0.7, cex.lab.ab=0.5, cex.x=0.8,
    xlab='Variable', ylab='Frequency', add.legend=TRUE, 
    leg.lab=leg.lab, leg.col=leg.col, leg.title='color',
    mar=c(7,4,3,1), png.width=7, png.height=6)
general.bar_plot_by(freq=table(x), labels.ab=paste0('X', 1:15), 
    file.name='test3_barplot', col=col[2,5],
      xlab='Number', ylab='Frequency')
general.bar_plot_by(freq=table(x), labels.ab=paste0('X', 1:15), 
    file.name='test4_barplot', col=col[2,5], mar=c(7,4,3,1),
    xlab='Number', ylab='Frequency', add.legend=TRUE, 
    leg.title='color', leg.col=leg.col[4], leg.lab=leg.lab[4])

## End(Not run)

jhooge/BioViz documentation built on May 19, 2019, 9:28 a.m.