PlotLong: Wrapper for fitting model and adjusting to predicted values...

Description Usage Arguments Value Author(s) Examples

Description

Wrapper for fitting model and adjusting to predicted values and passing newly fitted model to ggplot geom_stat_ribbon

Usage

1
2
PlotLong(data, mapping = NULL, model = lm, model.per = NULL,
  model.formula = NULL, facet.fun = NULL, plot.style = "ribbons", ...)

Arguments

data

data to use for model fitting and plotting

mapping

ggplot aesthetic mapping to use for plotting

model

model function to use for fitting; defaults to lm

model.per

grouping variables by which to isolate individual models

model.formula

model formula to use for model fitting

facet.fun

function to use for ggplot faceting in ggplot2::facet_grid

plot.style

one of 'errorbars' or 'ribbons'

...

Additional arguments allow for an assortion of additional functionality.

  • "Aesthetics" First, arguments which can be used as any of ggplot's default aesthetics will be pulled from ... args. .

  • "ggplot layers" Arguments are passed to underlying ggplot components by prefixing value with ggplot call name. ("ribbons", "line", "text", "facet", "xlab", "ylab", "labs" or "theme" - e.g. ribbons.color = 'red')).

  • "Model fitting" Arguments with prefixes of "model" will be passed to the model function if one is provided.

  • "ggpackets" Additional arguments passed to ggpk_ribbons or ggpk_line_errorbar.

Value

a ggplot object

Author(s)

Doug Kelkhoff [email protected]

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
# load data
nasa.data <- as.data.frame(dplyr::nasa)

# default representation
PlotLong(nasa.data, x = month, y = temperature)

# a more appropriate representation for large n
PlotLong(nasa.data, x = month, y = temperature, fun.data = 'quartiles')

# include linear adjustment accounting for amount of ozone
PlotLong(nasa.data, x = month, y = temperature,
         formula = temperature ~ ozone, fun.data = 'deciles',
         show.counts = T)

# adjusting by independent models for the northern and southern hemispheres
library(dplyr) # needed for %>%
PlotLong(nasa.data %>% mutate(hemi=ifelse(lat>0, "North", "South")),
         x = month, y = temperature, formula = temperature ~ ozone,
         model.per = ~ hemi, facet.fun = ~ hemi, fun.data = 'deciles',
         xlab = "Month", ylab = "Temperature Adjusted for Ozone",
         labs.title = "Temperature by Hemisphere",
         labs.caption = "*idependent models fit per hemisphere")

# including a table of value counts and subsetting value data to specific
# months
library(dplyr) # needed for %>%
PlotLong(nasa.data %>% mutate(hemisphere=ifelse(lat > 0, "North", "South")),
         x = month, y = temperature, group = hemisphere,
         color = hemisphere, fill = hemisphere,
         formula = temperature ~ ozone,
         model.per = ~ hemisphere, fun.data = 'deciles',
         plot.style = 'errorbars',
         show.counts = 'table',
         label.data = . %>% filter(month %in% c(1, 6, 12)),
         label.hjust = 'inward',
         xlab = "Month", ylab = "Temperature Adjusted for Ozone",
         labs.title = "Temperature by Hemisphere",
         labs.caption = "*idependent models fit per hemisphere")

lengning/gClinBiomarker documentation built on May 9, 2019, 2:55 p.m.