standardise: Standardise a summary to sum to one.

Description Usage Arguments Examples

View source: R/standardise.r

Description

Standardise a summary to sum to one.

Usage

1
standardise(x, margin = integer())

Arguments

x

a condensed summary. Must have .count variable.

margin

margins to standardise along. If NULL, the default, standardises the whole array.

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
b1 <- condense(bin(movies$year, 1))
d1 <- smooth(b1, 2, type = "reg")

if (require("ggplot2")) {

autoplot(b1)
autoplot(d1)

# Note change in x-axis limits
autoplot(standardise(d1))
}

# Can also standardise a dimension at a time
b2 <- with(movies, condense(bin(year, 2), bin(length, 10)))
b2 <- peel(b2, central = TRUE)

if (require("ggplot2")) {

autoplot(b2)
autoplot(standardise(b2))    # note legend
autoplot(standardise(b2, "year"))   # each row sums to 1
autoplot(standardise(b2, "length")) # each col sums to 1

base <- ggplot(b2, aes(length, .count)) +
  geom_line(aes(group = year, colour = year))
base
base %+% standardise(b2)  # Just affects y axis labels
base %+% standardise(b2, "year") # Makes year comparable
base %+% standardise(b2, "length") # Meaningless for this display

}

hadley/bigvis documentation built on May 17, 2019, 9:45 a.m.