-
Notifications
You must be signed in to change notification settings - Fork 27
/
plot_pairwise_orthologs.R
70 lines (62 loc) · 3.83 KB
/
plot_pairwise_orthologs.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
#' @title A line plot visualizing the number of pairwise orthologs within a ortho table generated with \code{\link{generate_ortholog_tables_all}}
#' @description Given a ortho table generated with \code{\link{generate_ortholog_tables_all}},
#' this function will visualize the number of pairwise orthologs inferred between a reference species A vs a set of subject species B_1, B_2, ...,B_N.
#' @param ortho_tables a \code{ortho tables} that was generated with \code{\link{generate_ortholog_tables_all}}.
#' @param species_order a character string specifying species names listed in the order of phylogenetic/taxonomic distance from the query species.
#' The species names must match with the species names present in the \code{ortho_tables}.
#' @param xlab x-axis label.
#' @param ylab y-axis label.
#' @param title plot title.
#' @param n_core_orthologs number of core orthologs within the \code{ortho tables}.
#' This number can be retrieved using \code{\link{retrieve_core_orthologs}}.
#' @author Hajk-Georg Drost
#' @export
plot_pairwise_orthologs <- function(ortho_tables, species_order, xlab = "Subject Species", ylab = "Number of reciprocal best hit orthologs", title = "", n_core_orthologs = NULL) {
subject_species <- NULL
ortholog_tbl_athaliana_pairwise <- dplyr::summarize(dplyr::group_by(ortho_tables, subject_species),
n_orthologs = dplyr::n())
ortholog_tbl_athaliana_pairwise$subject_species <- factor(
ortholog_tbl_athaliana_pairwise$subject_species,
levels = species_order
)
subject_species <- n_orthologs <- NULL
p <- ggplot2::ggplot(
ortholog_tbl_athaliana_pairwise,
ggplot2::aes(x = subject_species,
y = n_orthologs,
group = 1)
) + ggplot2::geom_line(size = 2) + ggplot2::geom_point(size = 4)
if (!is.null(n_core_orthologs)) {
p <- p + ggplot2::geom_abline(
intercept = n_core_orthologs,
size = 2,
col = "darkred",
alpha = 0.4
)
}
p <- p + ggplot2::geom_text(
ggplot2::aes(label = n_orthologs),
hjust = 0,
vjust = -1.5,
size = 6
) + ggplot2::scale_y_continuous(limits = c(0, max(ortholog_tbl_athaliana_pairwise$n_orthologs) + (max(ortholog_tbl_athaliana_pairwise$n_orthologs) / 10)),
breaks = scales::pretty_breaks(n = 10)) +
ggplot2::theme_minimal() +
ggplot2::labs(x = xlab, y = ylab, title = title) +
ggplot2::theme(
title = ggplot2::element_text(size = 18, face = "bold"),
legend.title = ggplot2::element_text(size = 18, face = "bold"),
legend.text = ggplot2::element_text(size = 18, face = "bold"),
axis.title = ggplot2::element_text(size = 18, face = "bold"),
axis.text.y = ggplot2::element_text(size = 18, face = "bold"),
axis.text.x = ggplot2::element_text(size = 18, face = "bold"),
panel.background = ggplot2::element_blank(),
strip.text.x = ggplot2::element_text(
size = 18,
colour = "black",
face = "bold"
)
) +
ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, vjust = 1, hjust = 1))
return(p)
}