facet_sample: Sample facets when ggplotting.

Description Usage Arguments Examples

View source: R/facet_sample.R

Description

facet_sample(...) does layout as in facet_grid(...), but samples facet(s) vice showing everything.

Usage

1
2

Arguments

...

facets, margins, etc - see facet_grid(...). The only eliminated parameter is drop - facet_sample(...) forces drop = TRUE

future: changed default for margin to show margins in the sampled dimension, though margin may be manually set to FALSE

sample_n

a length 2 integer array, optionally with one value NA_integer_; these values are the maximum number of rows (index 1) and columns (index 2) to show in facet_grid(...) layout (excluding margins). If sample_n exceeds the number of unique options in a dimension, facet_sample(...) will produce a warning.

a NA_integer_ entry (the default) will provide all the values in that facet, though facet_sample(...) will issue a warning if sample_n is left as default

future: a number between 0 and 1 will be treated as the fraction of options to be shown (converted to integer by ceiling)

seed

the random seed for drawing which rows & columns will be shown; by default, this is NA_integer_ and no seed will be set.

The random number generator is reset for both rows and columns (with an offset) so, with seed provided, changing the number of one dimension to display will not change which of the other dimensions are displayed.

The seed for each dimension may be independently specified with a 2 element 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
  # construct some data:
  sampn <- 10000

  testdata <- data.frame(
    rowcat = paste0("1", sample(LETTERS[1:10], sampn, replace = TRUE)),
    rowcat2 = paste0("2", sample(LETTERS[11:15], sampn, replace = TRUE)),
    colcat = paste0("2", sample(letters[1:10], sampn, replace = TRUE)),
    x = runif(sampn),
    y = runif(sampn)
  )

  p <- ggplot2::ggplot(testdata) + ggplot2::aes(x=x, y=y, color=rowcat2) +
    ggplot2::geom_point()

  # plot the works (not actually recommended)
  ## Not run: p + ggplot2::facet_grid(rowcat ~ colcat)

  # plot a sample of the row-facets:
  p + facet_sample(rowcat ~ colcat, sample_n = c(3, NA))

  # plot a sample of the column-facets:
  p + facet_sample(rowcat ~ colcat, sample_n = c(NA, 3))

  # plot a sample of all facets:
  p + facet_sample(rowcat ~ colcat, sample_n = c(3, 3))

ggFacetSample documentation built on Nov. 28, 2017, 5:01 p.m.