Skip to content

Commit

Permalink
Passed CHECK.
Browse files Browse the repository at this point in the history
  • Loading branch information
Venelin Mitov committed Oct 22, 2019
1 parent be89f50 commit c95a185
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 19 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
@@ -1,2 +1,3 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.travis\.yml$
5 changes: 3 additions & 2 deletions DESCRIPTION
Expand Up @@ -22,12 +22,13 @@ Depends:
Imports:
PCMBase,
PCMFit,
ggplot2
ggplot2,
ggtree,
data.table
Suggests:
testthat,
knitr,
rmarkdown,
ggtree,
cowplot,
BiocManager
RoxygenNote: 6.1.1
Expand Down
8 changes: 6 additions & 2 deletions NAMESPACE
Expand Up @@ -3,7 +3,11 @@
export(PlotRCPHistory)
import(PCMBase)
import(PCMFit)
import(ggplot2)
import(ggtree)
importFrom(data.table,":=")
importFrom(data.table,data.table)
importFrom(data.table,setkey)
importFrom(ggplot2,aes)
importFrom(ggplot2,geom_text)
importFrom(ggplot2,ggtitle)
importFrom(ggtree,"%<+%")
importFrom(ggtree,geom_nodepoint)
44 changes: 31 additions & 13 deletions R/PlotRCPHistory.R
Expand Up @@ -14,30 +14,37 @@
#' }
#' @param fit an object of S3 class `PCMFitModelMappings` returned by a call
#' to `PCMFitMixed`.
#' @param sizeGreyNodepoints,sizeColorNodepoints,sizeBlackAllowedModelTypes,sizeColorAllowedModelTypes,sizeRankInQueue,vjustBlackAllowed,vjustColorAllowedModelTypes graphical parameters (see function description).
#' @param sizeGreyNodepoints,sizeColorNodepoints,sizeBlackAllowedModelTypes,sizeColorAllowedModelTypes,sizeRankInQueue,vjustBlackAllowedModelTypes,vjustColorAllowedModelTypes
#' graphical parameters (see function description).
#' @param ... additional parameters passed to \code{\link{PCMTreePlot}}.
#' @return a list of annotated ggtree plots. Some of the entries in this list
#' can be NULL to indicate that no score improvement has been achieved at the
#' corresponding iteration. The example below shows how to filter these out.
#'
#' @importFrom data.table data.table setkey
#' @importFrom data.table data.table setkey :=
#' @importFrom ggtree geom_nodepoint %<+%
#' @importFrom ggplot2 ggtitle geom_text aes
#' @import PCMBase
#' @import PCMFit
#' @import ggtree
#' @import ggplot2
#'
#' @examples
#' lstPlots <- PlotRCPHistory(
#' fitMappings_MGPM_B_best_clade_2_DataWithSEs, layout = "fan")
#' fitBMWithShiftsToMammalData, layout = "fan")
#' cowplot::plot_grid(plotlist = lstPlots[!sapply(lstPlots, is.null)])
#'
#' @export
PlotRCPHistory <- function(
fit,
sizeGreyNodepoints = 2.2, sizeColorNodepoints = 2.2,
sizeBlackAllowedModelTypes = 1.4, sizeColorAllowedModelTypes = 1.4, sizeRankInQueue = 1.4,
sizeBlackAllowedModelTypes = 1.4, sizeColorAllowedModelTypes = 1.4,
sizeRankInQueue = 1.4,
vjustBlackAllowedModelTypes = -1.6, vjustColorAllowedModelTypes = -1.6,
...) {

# Avoiding CRAN check warnings
node <- selected <- candidate <- rankInQueue <- .I <- allowedModelTypes <-
allowedModelTypesSelected <- allowedModelTypesCandidate <- NULL

tree <- PCMTree(fit$tree)

treeRootInt <- PCMTreeNumTips(tree) + 1L
Expand Down Expand Up @@ -95,10 +102,10 @@ PlotRCPHistory <- function(
})]

dtCladePartition[
node%in%historyEntry$headQPR_Partition,
node %in% historyEntry$headQPR_Partition,
allowedModelTypesSelected:=allowedModelTypes]
dtCladePartition[
!(node%in%historyEntry$headQPR_Partition),
!(node %in% historyEntry$headQPR_Partition),
allowedModelTypesCandidate:=allowedModelTypes]

fitTablei <- RetrieveFittedModelsFromFitVectors(
Expand All @@ -112,13 +119,24 @@ PlotRCPHistory <- function(
palette <- colorsForPartNodes[as.character(historyEntry$headQPR_Partition)]
names(palette) <- as.character(PCMTreeGetRegimesForNodes(tree, nodes = as.integer(historyEntry$headQPR_Partition)))

ploti <- PCMTreePlot(tree, palette = palette, ...) %<+% as.data.frame(dtCladePartition) %<+% as.data.frame(remainingQueuei) +
ploti <- PCMTreePlot(tree, palette = palette, ...) %<+%
as.data.frame(dtCladePartition) %<+% as.data.frame(remainingQueuei) +
geom_nodepoint(aes(shape=selected), size=sizeColorNodepoints, na.rm = TRUE) +
geom_nodepoint(aes(shape=candidate), size=sizeGreyNodepoints, color = "grey", na.rm = TRUE) +
geom_text(aes(label=allowedModelTypesSelected), size=sizeColorAllowedModelTypes, vjust=vjustColorAllowedModelTypes) +
geom_text(aes(label=allowedModelTypesCandidate), color = "black", size=sizeBlackAllowedModelTypes, vjust=vjustBlackAllowedModelTypes) +
geom_text(aes(label=rankInQueue), color="black", size=sizeRankInQueue) +
ggtitle(paste0("(",i,") score=", round(fitTablei$score[[1]]), ", logLik=", round(fitTablei$logLik[[1]]), ", p=", fitTablei$df[[1]]))
geom_text(aes(label=allowedModelTypesSelected),
size=sizeColorAllowedModelTypes,
vjust=vjustColorAllowedModelTypes) +
geom_text(aes(label=allowedModelTypesCandidate),
color = "black",
size=sizeBlackAllowedModelTypes,
vjust=vjustBlackAllowedModelTypes) +
geom_text(aes(label=rankInQueue),
color="black",
size=sizeRankInQueue) +
ggtitle(paste0("(",i,") score=",
round(fitTablei$score[[1]]),
", logLik=", round(fitTablei$logLik[[1]]),
", p=", fitTablei$df[[1]]))

ploti
} else {
Expand Down
5 changes: 5 additions & 0 deletions R/data.R
@@ -0,0 +1,5 @@
#' An example model fit of BM model with shifts to a large phylogenetic tree
#' with bivariate trait data.
#'
#' @format This is a list with assigned S3 class `PCMFitModelMappings`.
"fitBMWithShiftsToMammalData"
Binary file added data/fitBMWithShiftsToMammalData.rda
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions man/PlotRCPHistory.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions man/fitBMWithShiftsToMammalData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c95a185

Please sign in to comment.