plot_counts: Horizontal Bar Plot of Group Counts

Description Usage Arguments Value Examples

View source: R/plot_counts.R

Description

Plot the counts of groups within a vector or list as a horizontal bar plot.

Usage

1
2
3
4
5
6
7
8
9
plot_counts(
  x,
  n = NULL,
  percent = TRUE,
  item.name = "Terms",
  rev = FALSE,
  drop = TRUE,
  ...
)

Arguments

x

A vector or list of elements.

n

Minimum frequency to be shown in the plot. If NULL all are shown.

percent

logical. If TRUE the x axis is scaled as percentages. Otherwise, the x axis is counts.

item.name

The name of the variable that contains the groups (different element in the vector/list).

rev

logical. If TRUE the bars go from least to greatest.

drop

logical. If FALSE and x is an as_terms object created from a term_count object, then unfound terms will not be dropped.

...

ignored.

Value

ggplot2 object.

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
x <- sample(LETTERS, 100, TRUE)
y <- lapply(1:100, function(i) sample(LETTERS[1:10], sample(0:5, 1), TRUE))
y <- sapply(y, function(x) {
    if(identical(x, character(0))) return(NULL)
    x
})

plot_counts(x)
plot_counts(y)

## Example
library(dplyr)
data(presidential_debates_2012)

discoure_markers <- list(
    response_cries = c("\\boh", "\\bah", "\\baha", "\\bouch", "yuk"),
    back_channels = c("uh[- ]huh", "uhuh", "yeah"),
    summons = "hey",
    justification = "because"
)

presidential_debates_2012 %>%
    with(., term_count(dialogue, TRUE, discoure_markers)) %>%
    as_terms() %>%
    plot_counts() +
        ggplot2::xlab("Tags")

presidential_debates_2012 %>%
    with(., term_count(dialogue, TRUE, discoure_markers)) %>%
    as_terms() %>%
    plot_freq(size=3) +
        ggplot2::xlab("Number of Tags")

presidential_debates_2012 %>%
    with(., term_count(dialogue, TRUE, discoure_markers)) %>%
    as_terms() %>%
    plot_counts(percent=FALSE, item.name = "Tags")

trinker/termco documentation built on Jan. 7, 2022, 3:32 a.m.