Learn R Programming

ggbash (version 0.4.5)

ggbash: execute a specified ggbash command

Description

ggbash() can be used as follows: 1. ggbash() : with no argument (enter into an interactive ggbash session) 2. ggbash("gg mtcars + point mpg cyl") : with a character argument 3. ggbash( gg(mtcars) + point(mpg,cyl)) : with ggbash commands and a dataset 4. mtcars

Usage

ggbash(ggbash_symbols = "", clipboard = NULL, show_warn = TRUE,
  as_string = FALSE)

Arguments

ggbash_symbols

Non-evaluated R symbols or a character representing ggbash commands. If no ggbash_symbols are specified, enter into an interactive ggbash session.

clipboard

Default is NULL. If non-null, copy the resulted string to clipboard.

show_warn

If ambiguously matched, display warning. Default is TRUE.

as_string

Return a string instead of a ggplot2 object. Default is FALSE.

Details

In 1 and 2 cases, parentheses and commas are optional in ggbash commands, whereas 3 and 4 can only interpret commands with parentheses and commas because of R's default token constraints.

ggbash features partial match for the following elements: 1. ggplot() function (any of ggplot(), gg() and g() works) 2. geom names (geom_point can be specified by point or even p) 3. aesthetics names (size by sz, color by col or c ) 4. column names (prefix match only, no fuzzy match. When ambiguous, the column with the smallest column index is used) 5. theme element names (legend.text by l.txt, axis.title.x by a.ttl.x)

Examples

Run this code
# NOT RUN {
# Case 1: ggbash() with no argument

ggbash() # ggbash() enters into an interactive ggbash session

# Case 2: with a character arugment

## parentheses and commas become optional

ggbash("gg iris  + point Sepal.W  Sepal.L  color=Species ")
ggbash("gg iris  + point Sepal.W, Sepal.L, color=Species ")
ggbash("gg(iris) + point(Sepal.W, Sepal.L, color=Species)")

## all of the above work


# Case 3: with a short-ggplot2 command

## sm: geom_smooth
ggbash(gg(iris, Sepal.W, Sepal.L, c=Sp) + point + sm(method="lm", se=FALSE)
       + theme(a.txt(sz=25, face="bold"), l.pos("bottom")) )

## if you prefer more ggplot2-compliant syntax
ggbash(ggplot(iris, Sepal.Width, Sepal.Length, colour = Species) +
       geom_point() + geom_smooth(method = "lm", se = FALSE) +
       theme(axis.text(size=25, face="bold"), legend.position("bottom")) )

## or if you prefer an extreme short syntax
ggbash(g(iris, Sepal.W, S, c=Sp) + p + sm(mth="lm", se=FALSE)
       + theme(a.tx(s=25, f="bold"), l.pos("bottom")))

## S ambiguously matches to Sepal.Length, Sepal.Width, Species.
## Since the Sepal.Length has the smallest column index, it's selected


# Case 4: dataset piped from dplyr/tidyr

iris %>%
    mutate(my_long_descriptive_column_name = Sepal.Width,
           other_useful_informative_name = Sepal.Length) %>%
    ggbash(gg() + point(my, other))

# }
# NOT RUN {
# }

Run the code above in your browser using DataLab