plot_columns: Given a set of columns of data in a time series plot the data...

Description Usage Arguments Value Examples

Description

Given a set of columns of data in a time series plot the data over time.

Usage

1
2
plot_columns(data_, col_names, col_prefix = stringr::str_sub(col_names[1], end
  = -3))

Arguments

data_

The dataframe containing the columns to plot.

col_names

Character vector of columns to plot.

col_prefix

The prefix all the columns have in common. Defaults to the first column name with the final two characters removed.

Value

a ggplot2 object for the columns that were checked

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
data_to_plot <- data.frame(smk80 = c('never', 'past', 'never'),
                           smk82 = c('past', 'never', 'past'),
                           smk84 = c('never', 'never', 'past'))
plot_columns(data_to_plot, generate_column_names('smk', from = 1980, to = 1984))

# You can also capture the plot returned and modify it.
numeric_data_to_plot <- data.frame(
                           bmi80 = rnorm(200, mean = 30, sd = 3),
                           bmi82 = rnorm(200, mean = 31, sd = 2.8),
                           bmi84 = rnorm(200, mean = 32, sd = 2.5))
p <- plot_columns(numeric_data_to_plot,
                  generate_column_names('bmi', from = 1980, to = 1984))
# Show default plot
p
# Modify default plot to zoom in by changing the limits
library(ggplot2)
p + ylim(27, 35)

# Modify the default plot to invert the X and Y axes and use
# a different theme.
p + coord_flip() + theme_minimal()

nurseshealthstudy/Nurses documentation built on May 14, 2019, 3:08 a.m.