prettybars2: prettybars2

Description Usage Arguments See Also Examples

View source: R/plot_special.R

Description

A barplot.

Usage

1
2
3
4
5
6
7
prettybars2(x, lab.y = colnames(x), n.y = ncol(x),
  lab.group = rownames(x), n.group = nrow(x),
  col.group = adjustcolor(seq.int(n.group), alpha.f = 0.5),
  col.line = "skyblue3", extra.margin = 0, col.bg = "snow", cex.y = 0.7,
  notext = FALSE, title = paste0("prettybar of ", m$x),
  sub = paste0("     n = ", sum(x)), note = NULL,
  subnote = "subnote: here is a subnote", legend = 1L, ...)

Arguments

x

a table of data, typically from table or xtabs

lab.y

y-axis labels

n.y

number of y-groups (calculated from x)

lab.group

group labels

n.group

number of groups (calculated from x)

col.group

color for each group level

col.line

color of origin line

extra.margin

extra left spacing for long lab.y labels

col.bg

background color

cex.y

size of lab.y

notext

logical; if TRUE, suppresses all plot text, labels, and axes for user input

title, sub

main and sub titles

note, subnote

optional note (top right) or subnote (bottom right)

legend

integer (0, 1, 2); 0 for no legend; 1 for a legend with pre-formatting; or 2 for a default legend

...

additional graphical parameters passed to par

See Also

prettybars; bibar

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
set.seed(1)
f <- function(...) sample(1:5, 100, replace = TRUE, prob = c(...))
dat <- data.frame(q1 = f(.1, .2, .3, .3, .1),
                  q2 = f(.1, .4, .1, .3, .1),
                  q3 = f(.1, .2, .3, .3, .1),
                  q4 = f(.1, .1, .3, .3, .1),
                  q5 = f(.2, .1, .2, .3, .2),
                  q6 = f(.1, .3, .3, .2, .1),
                  q7 = f(.1, .4, .1, .1, .3))
dat <- stack(dat)
dat <- within(dat, {
  values <- factor(values, levels = 1:5, labels = c('NA','SA','A','D','SD'))
})

tdat <- table(dat)
cols <- c(
  grey(.9),
  adjustcolor(c('cadetblue', 'lightblue', 'lightpink', 'red'), alpha.f = 0.5)
)
               
## compare:
barplot(tdat, horiz = TRUE, las = 1, col = cols, border = NA)
prettybars2(tdat, lab.y = paste('Question #', 1:7), extra.margin = 3,
            col.group = cols)

## using bibar
par(mar = c(5, 8, 4, 2))
at <- bibar(t(tdat), 3:2, 4:5, 1, col = cols,
            xlim = c(-80, 50), axes = FALSE)

axis(1, pretty(c(-80, 50)), abs(pretty(c(-80, 50))))
abline(v = 0, col = 'lightblue', lwd = 4)
text(-85, at, sprintf('Question # %s', 1:7), xpd = NA, adj = 1)

legend('topleft', inset = c(0, -0.2), xpd = NA, fill = cols[2:3],
       legend = rownames(tdat)[2:3], horiz = TRUE, bty = 'n')
legend('topright', inset = c(0, -0.2), xpd = NA, fill = cols[4:5],
       legend = rownames(tdat)[4:5], horiz = TRUE, bty = 'n')

raredd/plotr documentation built on Nov. 13, 2018, 7:05 a.m.