m_trait_recon: Plot MuHiSSE model-averaged marginal ancestral state...

Description Usage Arguments Value Examples

View source: R/utilhisse.R

Description

A function to plot a MuHiSSE (model-averaged) marginal ancestral reconstruction for the trait data.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
m_trait_recon(
  processed_recon,
  show_tip_labels = FALSE,
  cutoff = c(0.2, 0.2),
  states_of_first_character,
  states_of_second_character,
  tree_layout = "rectangular",
  tree_direction = "right",
  time_axis_ticks = 10,
  open_angle = 10,
  colors = viridis(n = 9)
)

Arguments

processed_recon

An object produced by m_process_recon

show_tip_labels

Logical, whether to plot tip labels. Default is FALSE because it is difficult to plot legible tip labels for larger trees common in this type of analysis. See ?m_trait_recon for a good manual solution.

cutoff

A vector of length 2 giving the values for discretizing the reconstructed probabilities for the first and second character. Categories "0", "uncertain", or "1" are assigned to probabilities >= 1-cutoff, 1-cutoff:cutoff, <=cutoff. A cutoff=0.5 will result with four categories, essentially ignoring the uncertainty in ancestral state reconstruction. A cutoff < 0.5 will produce a category "uncertain" for probabilities in the range 1-cutoff:cutoff. The function will print a count of the categories after discretizing, so it is possible to adjust the cutoff values to avoid plotting of categories with too few nodes

states_of_first_character

Translation for the character states

states_of_second_character

Translation for the character states

tree_layout

A layout for the tree. Available options are 'rectangular' (default), 'slanted', 'circular', 'fan' and 'radial'.

tree_direction

'right' (default), 'left', 'up', or 'down' for rectangular and slanted tree layouts

time_axis_ticks

numeric giving the number of ticks for the time axis (default=10). Passed on to pretty internally, so the number of plotted ticks might not be exactly the same.

open_angle

The degrees of empty space between the first and last tip. Only works for tree_layout = 'fan' and allows for a little more space around axis tick labels.

colors

A vector of colors for the character states. Note that the number of categories depends on the cutoff value. Internally this vector of colors is subset to colors[1:number of states], so some tinkering might be necessary to get colors that work well together.

Value

A plot of the phylogeny with branches colored by muhisse-inferred marginal ancestral states.

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
data("diatoms")
processed_muhisse <- m_process_recon(muhisse_recon=diatoms$muhisse_recon)
cols = c("#00204DFF", "#1B3B6DFF", "#4E576CFF", "#727274FF", "#958F78FF", "#BCAF6FFF", "#E7D159FF")
# eight categories after binning with a cutoff of 0.2
m_trait_recon(
 processed_recon = processed_muhisse,
 cutoff = c(.2, .2),
 states_of_first_character = c("marine", "freshwater"),
 states_of_second_character = c("plankton", "benthos"),
 tree_layout = "radial",
 colors = cols)

# three of these eight have < 3 nodes, so we could try to avoid plotting some of them
# adjust the cutoff for the second variable

m_trait_recon(
 processed_recon = processed_muhisse,
 cutoff = c(.2, .3),
 states_of_first_character = c("marine", "freshwater"),
 states_of_second_character = c("plankton", "benthos"),
 tree_layout = "radial",
 colors = cols)

# ignoring uncertainty
m_trait_recon(
 processed_recon = processed_muhisse,
 cutoff = c(.5, .5),
 states_of_first_character = c("marine", "freshwater"),
 states_of_second_character = c("plankton", "benthos"),
 tree_layout = "radial",
 colors = cols)



#'# Plotting tip labels
# for better control over font size, justification, alignment, and offset
# use show_tip_labels= FALSE and add the tip labels manually
#
# for example

require("ape")
data("diatoms")
x <- m_process_recon(diatoms$`3state_musse_recon`)

# the defaults work poorly
m_trait_recon(processed_recon = x,
 show_tip_labels= TRUE,
 states_of_first_character = c("0", "1"),
 states_of_second_character = c("0", "1"))

# manual setup is better
basic_plot <-
 m_trait_recon(
 processed_recon = x,
 show_tip_labels= FALSE,
 states_of_first_character = c("0", "1"),
 states_of_second_character = c("0", "1"),
 time_axis_ticks = 8
)

# extract the data component from the ggplot object
# we'll need it to order the tip labels
plot_data <- basic_plot$data %>%
 filter(isTip == TRUE) %>% # we need the tips only, no nodes
 arrange(y) # sort numerically

basic_plot +
 #now add an axis to the right
 scale_y_continuous(position = "right",
                    breaks = plot_data$y,
                    labels = plot_data$label) +
 # enable the axis text, but disable the line and ticks marks
 # move the legend out of the way
 theme(
   legend.position = "top",
   axis.ticks.y = element_blank(),
   axis.line.y = element_blank(),
   axis.text.y = element_text(face = "italic")
 )

teofiln/utilhisse documentation built on Sept. 3, 2020, 2:55 p.m.