talk_ggplot: Talk to ggplot a Data set

Description Usage Arguments Value Examples

View source: R/talk_ggplot.R

Description

Talk to ggplot a Data set

Usage

1
2
3
4
5
talk_ggplot(.data, cmd, verbose = FALSE, ...)

talk_ggplot_expr(data_colnames, cmd, allowed_words = talk_ggplot_words(), ...)

talk_process_ggplot_cmd(cmd)

Arguments

.data

The data set/data.frame to perform the operation.

cmd

Command to perform on the data set.

verbose

print diagnostic output

...

additional arguments to pass to talk_get_colnames

data_colnames

column names of the data

allowed_words

words allowed to be in the command other than the column names

Value

A data.frame or list of them if length(cmds) > 1.

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
library(tibble)
library(dplyr)
df = mtcars %>%
  rownames_to_column(var = "car")

  cmds = c(
    "ggplot by  mpg",
    "ggplot by  column    mpg  ",
    "plot mpg filled with gear",
    "ggplot by column 5 and column 4",
    "ggplot a histogram of mpg, coloured by gear",
    "ggplot columns 4 and 5",
    # duplciate
    "ggplot by mpg coloured by gear")
 data_colnames = df
 .data = df
 allowed_words = talkr:::talk_ggplot_words()
 cmd = c(
 "ggplot by mpg coloured by gear",
 "ggplot a histogram of mpg, coloured by gear",
 "ggplot a histogram of mpg, facetted by gear")
 results = lapply(cmds, talk_ggplot_expr, data_colnames = df)
 results = lapply(cmds, talk_ggplot, .data = df)
 cmd =  "ggplot by columns 2 and 5"
 cmd = "ggplot MPG faceted by gear"
 testthat::expect_silent(talk_ggplot(.data, cmd))
df = df %>%
  rename(GEAR = gear)
 gear = df %>%
 talk_ggplot("ggplot by gear and column 3")
print(gear)

muschellij2/talkr documentation built on Jan. 20, 2020, 7:49 p.m.