/
sensi_plot.tree.physig.R
122 lines (117 loc) · 5.18 KB
/
sensi_plot.tree.physig.R
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#' Graphical diagnostics for class 'tree.physig'
#'
#' \code{sensi_plot_tree.physig} Plot results from \code{tree_physig}.
#' @param x output from \code{tree_physig}
#' @param graphs choose which graph should be printed in the output ("all", 1 or 2)
#' @param ... further arguments to methods
#' @importFrom ggplot2 scale_color_manual geom_histogram geom_abline geom_density
#' geom_vline xlab geom_point theme
#' @author Caterina Penone and Gustavo Paterno
#' @seealso \code{\link[ggplot2]{ggplot}}, \code{\link[sensiPhy]{tree_phylm}}
#' \code{\link[sensiPhy]{intra_phylm}}
#' @details For 'x' from \code{tree_physig}
#'
#' \strong{Graphs 1:} Distribution of estimated phylogenetic signal (lambda or K) for each tree
#' Red vertical line represents the average signal among all estimates.
#'
#' \strong{Graph 2:} Distribution of p-values for the phylogenetic signal (K or lambda)
#' for each tree. Red vertical line represents the alpha significance level = 0.05.
#' @importFrom grid unit
#' @importFrom stats plogis
#' @importFrom stats reorder
#' @export
sensi_plot.tree.physig <- function(x, graphs="all", ...){
### Nulling variables
pval <- DIFestimate <- Estimate <- Significant <- Species.removed <- NULL
element_line <- estimate <- geom_jitter <- NULL
### Basic checking:
method <- x$call$method
if(is.null(x$call$method)) method <- "K"
### Distribution of K values estimated
e1 <- ggplot2::ggplot(x$tree.physig.estimates, aes(x=estimate))+
geom_histogram(fill="yellow",colour="black", size=.2,
alpha = .3) +
geom_vline(xintercept = x$stats$mean[1], color="red",linetype=2,size=.7)+
xlab(paste("Estimated", method, "values", sep = " "))+
ylab("Frequency")+
theme(axis.title=element_text(size=12),
axis.text = element_text(size=12),
panel.background = element_rect(fill="white",
colour="black"))
### Distribution of Values estimated
e2 <- ggplot2::ggplot(x$tree.physig.estimates, aes(x = pval))+
geom_histogram(fill="yellow",colour="black", size=.2,
alpha = .3) +
geom_vline(xintercept = 0.05,color="red",linetype=1,size=.7)+
#scale_x_continuous(limits = c(0,1), breaks = seq(0,1,.1))+
xlab("Estimated P values")+
ylab("Frequency")+
theme(axis.title=element_text(size=12),
axis.text = element_text(size=12),
panel.background = element_rect(fill="white",
colour="black"))
### Plotting:
if (graphs=="all")
suppressMessages(return(multiplot(e1,e2, cols=2)))
if (graphs==1)
suppressMessages(return(e1))
if (graphs==2)
suppressMessages(return(e2))
}
#' Graphical diagnostics for class 'intra.physig'
#'
#' \code{sensi_plot_intra.physig} Plot results from \code{intra_physig}.
#' @param x output from \code{intra_physig}
#' @param graphs choose which graph should be printed in the output ("all", 1 or 2)
#' @param ... further arguments to methods
#' @importFrom ggplot2 scale_color_manual geom_histogram geom_abline geom_density
#' geom_vline xlab geom_point theme
#' @author Caterina Penone and Gustavo Paterno
#' @seealso \code{\link[ggplot2]{ggplot}}, \code{\link[sensiPhy]{intra_phylm}}
#' \code{\link[sensiPhy]{intra_phylm}}
#' @details For 'x' from \code{intra_physig}
#'
#' Graphs 1: Distribution of estimated phylogenetic signal (lambda or K) for each simulation
#' Red vertical line represents the average signal among all estimates.
#'
#' Graph 2: Distribution of p-values for the phylogenetic signal (K or lambda)
#' for each simulation. Red vertical line represents the alpha significance level = 0.05.
#' @importFrom grid unit
#' @importFrom stats plogis
#' @export
sensi_plot.intra.physig <- function(x, graphs="all", ...){
### Nulling variables:
estimate <- pval <- NULL
### Basic checking:
method <- x$call$method
if (is.null(x$call$method)) method <- "K"
### Distribution of K values estimated
e1 <- ggplot2::ggplot(x$intra.physig.estimates, aes(x = estimate)) +
geom_histogram(fill = "yellow",colour = "black", size = .2,
alpha = .3) +
geom_vline(xintercept = x$stats$mean[1], color = "red", linetype = 2, size = .7) +
xlab(paste("Estimated", method, "values", sep = " ")) +
ylab("Frequency") +
theme(axis.title = element_text(size = 12),
axis.text = element_text(size = 12),
panel.background = element_rect(fill = "white",
colour = "black"));
### Distribution of Values estimated
e2 <- ggplot2::ggplot(x$intra.physig.estimates, aes(x = pval)) +
geom_histogram(fill = "yellow", colour = "black", size = .2,
alpha = .3) +
geom_vline(xintercept = 0.05, color = "red", linetype = 1, size = .7) +
xlab("Estimated P values") +
ylab("Frequency") +
theme(axis.title = element_text(size = 12),
axis.text = element_text(size = 12),
panel.background = element_rect(fill = "white",
colour = "black"));
### Plotting:
if (graphs == "all")
suppressMessages(return(multiplot(e1,e2, cols = 2)))
if (graphs == 1)
suppressMessages(return(e1))
if (graphs == 2)
suppressMessages(return(e2))
}