prepare_by_group_trend_graph: Prepares a By Group Trend Graph

Description Usage Arguments Value Examples

View source: R/prepare_by_group_trend_graph.R

Description

Reads a data frame and line plots the selected variables (which need to be numeric) by group and an ordered factor (normally the time-series indicator).

Usage

1
2
3
4
5
6
7
8
prepare_by_group_trend_graph(
  df,
  ts_id,
  group_var,
  var,
  points = TRUE,
  error_bars = FALSE
)

Arguments

df

Data frame containing the ordered factor and a set of numerical variables to be plotted.

ts_id

a string containing the column name of the ordered factor (normally the time-series indicator).

group_var

a variable coercible into a factor to group the data on.

var

The name of the variable that you want to plot.

points

Do you want points to indicate the observations? Defaults to TRUE.

error_bars

Do you want error bars to be plotted? Defaults to FALSE.

Value

A list containing two items:

"df"

A data frame containing the plotted means and standard errors by group

"plot

The plot as returned by ggplot

Examples

1
2
3
4
df <- worldbank
df$gdp_capita <- worldbank$NY.GDP.PCAP.KD
graph <- prepare_by_group_trend_graph(df, "year", "region", "gdp_capita")
graph$plot

ExPanDaR documentation built on Jan. 8, 2021, 5:36 p.m.