add_lines: Add data to a ggplot

View source: R/plot.R

add_linesR Documentation

Add data to a ggplot

Description

Add a lineplot of the *x_key* and *y_key* columns in *data* to the supplied ggplot object *ax*. If none is supplied, a new one is created.

Usage

add_lines(
  data,
  ax = NULL,
  y_key = "dBM_smooth",
  x_key = "DOY",
  style = "line",
  label = NULL,
  ...
)

Arguments

data

data.frame or similar object interpretable by ggplot.

ax

list as returned by ggplot() and related functions.

x_key, y_key

Column names in *data* to be plotted.

style

XXX in ggplot geom_XXX to use.

label

Codename for this line to be used in legend creation. If NULL, use *y_key*.

...

All further arguments are passed to the selected ggplot geom.

Value

ax A ggplot list (like the input *ax*).

Examples

library(ggplot2)
# Add first set of data
ax = add_lines(mtcars, x_key = "wt", y_key = "mpg", label = "First Line")

# Add one more line to the plot
ax = add_lines(mtcars, ax = ax, x_key = "wt", y_key = "qsec", 
label = "Second Line")

print(ax)

growR documentation built on May 29, 2024, 9:12 a.m.