plot_cline: Plot a cline

Description Usage Arguments Details Value Examples

View source: R/plot_cline.R

Description

Makes a simple plot to visualize modeled genetic or phenotypic clines. The user supplies the stanfit object containing the model fit and the dataframe with the original data, and may also supply a number of optional arguments to customize the plot.

Usage

1
2
3
plot_cline(stanfit, data, best.fit.line = "mean", add.obs = F,
  confidence = F, prob = 0.95, method = "HPDI",
  cline.col = "black", point.col = "black", clear.cache = F, ...)

Arguments

stanfit

A stanfit object holding your model results.

data

The dataframe with your cline data (ideally, the same data frame that was used to generate the model fit).

best.fit.line

The point estimates to use for drawing the best fit line. Either "mean" for the mean of the posterior distribution of each paramer, or "median" for the median of the posterior distribution of each parameter. Default is "mean".

add.obs

Should the observed allele frequencies or trait values be plotted? TRUE or FALSE, default is FALSE.

confidence

Display credible intervals around the cline? TRUE or FALSE, default FALSE.

prob

The probability interval to calculate around the cline. Default is .95. Numeric, between 0 and 1.

method

The method for calculating credible intervals. Either "ET" for equal-tail probability intervals, or "HPDI" for highest posterior density intervals. Default is "HPDI".

cline.col

the color of the cline and confidence intervals. Default is black.

point.col

The color to use for plotting the observed trait values. Default is black.

clear.cache

Clear the cache of saved results to ensure recalculation predicted cline? TRUE or FALSE, default FALSE.

...

Further graphical parameters to be passed to the base R plotting functions to customize the plot (see par).

Details

This plotting function is mostly a wrapper around predict_cline. For greater customization of plots, users are encouraged to use predict_cline to generate the x- and y-coordinates for their fitted cline and confidence intervals, and then graph those coordinates using the plotting methods and packages of their choice (base plotting, lattice, or ggplot2).

Value

invisible(NULL)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 

# Default plot with the cline only
plot_cline(yourStanfit, data)

# Add points showing the observed raw data
plot_cline(yourStanfit, data, add.obs = T)

# Add credible intervals around the cline
plot_cline(yourStanfit, data, confidence = T)

# Some plot customization
# Adding axis labels, titles, and changing the
# colors of the points and line.
plot_cline(yourStanfit, data, add.obs = T,
                main = "My cline",
                xlab = "distance",
                ylab = "trait value",
                point.col = "red",
                col = "blue")

## End(Not run)

tjthurman/BAHZ documentation built on May 30, 2020, 8:28 a.m.