Skip to contents
loading...

chart() provides a unified interface for base plots, lattice and ggplot2.

Usage

chart(data, ..., type = NULL, env = parent.frame())

# S3 method for default
chart(
  data,
  specif = NULL,
  formula = NULL,
  mapping = NULL,
  ...,
  type = NULL,
  auto.labs = TRUE,
  env = parent.frame()
)

# S3 method for `function`
chart(data, ..., type = NULL, auto.labs = TRUE, env = parent.frame())

# S3 method for subsettable_type
$(x, name)

Arguments

data

The dataset (a data.frame or tibble, usually).

...

Further arguments.

type

The type of plot to produce.

env

The environment where to evaluated the formula.

specif

Specification, being either aes(), or a formula.

formula

A formula.

mapping

An aes() object, as for ggplot().

auto.labs

Are labels (and units) automatically used for axes?

x

A subsettable_type function.

name

The value to use for the type= argument.

Details

....

See also

Examples

urchin <- data.io::read("urchin_bio", package = "data.io", lang = "en")

# base R graphics
hist(urchin$height)

# ... translates to:
chart(function() hist(urchin$height))

# ... or if the expression is provided directly, specify it is a base chart
chart(hist(urchin$height), type = "base")


# ... or more concisely:
chart$base(hist(urchin$height))
#> Error in chart.default(type = name, ...): It seems no plot was generated with this code

# A lattice plot
histogram(~ height, data = urchin)
chart$histogram(urchin, ~ height)

# ggplot2 histogram
ggplot(urchin, aes(height)) + geom_histogram()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#... or with chart (notice similarities with lattice version)
chart(urchin,  ~ height) + geom_histogram()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#chart$geom_histogram(urchin,  ~ height)