ffplot: Fast Friendly Plot

Description Usage Arguments Details Value Examples

Description

Plots subsets of your data using ggplot.

Usage

1
2
3
4
5
6
## S3 method for class 'formula'
ffplot(formula, data = parent.frame(), ..., subset = NULL,
  smooth = NULL)

## Default S3 method:
ffplot(data, ...)

Arguments

formula

a two-sided formula. The right hand side must contain only one term (which can be an interaction, e.g. g1:g2).

data

a data frame

...

other arguments passed into (all) geoms

subset

an optional vector specifying a subset of the data

smooth

logical (not yet implemented!)

Details

The data is split into subsets for each unique value of the right hand side of formula. Each term on the left hand side of formula is evaluated within that subset, and the results are used to create a layer.

By default, geoms are chosen as follows: if the left hand side term evaluates to a character or factor, a histogram of proportions is plotted using geom_histogram. If the term is numeric and always returns a single value (e.g. mean(y)) then a line is plotted; if it always returns two values, vertical lines are used; otherwise points are plotted. Certain functions are automagically recognized, e.g. ci creates a geom_errorbar.

The default method simply calls ffplot.formula, passing its first argument as data. This plays nicely with dplyr.

Value

A ggplot object which can be printed or modified.

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
38
39
data(diamonds)
d30 <- diamonds[1:30,]

# numeric y variables:
ffplot(price ~ carat, d30)
ffplot(price ~ color, d30)

# non-numeric y:
ffplot(cut ~ color, d30)

# a function of your data:
ffplot(range(price) ~ color, d30)

# confidence intervals
ffplot(ci(price, 0.95) ~ color, d30)

# multiple plots:
ffplot(price + ci(price) ~ color, d30)

# choosing geoms:
ffplot(line(mean(price)) + ci(price, .99) ~ color, d30)
ffplot(violin(price) ~ color, diamonds)

# adding options:
ffplot(price, diamonds, geom = "point", shape = 3)

# adding options per y variable:
ffplot(point(price, alpha = 0.2, color = "red") + smooth(price, color = "orange", size = 2, se = TRUE) ~ carat, diamonds)

## Not run: 
# with dplyr
library(dplyr)
diamonds %>% ffplot(cut ~ color)


## End(Not run)
# Facetting:
ffplot(price ~ carat | color, diamonds)
ffplot(smooth(mean(price)) ~ carat | color + cut, diamonds)

hughjonesd/ffplot documentation built on May 17, 2019, 9:11 p.m.