diff --git a/.Rbuildignore b/.Rbuildignore index 91114bf..112ad26 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,3 @@ ^.*\.Rproj$ ^\.Rproj\.user$ +^\.travis\.yml$ diff --git a/DESCRIPTION b/DESCRIPTION index 602c248..cc8c36d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,12 +22,13 @@ Depends: Imports: PCMBase, PCMFit, - ggplot2 + ggplot2, + ggtree, + data.table Suggests: testthat, knitr, rmarkdown, - ggtree, cowplot, BiocManager RoxygenNote: 6.1.1 diff --git a/NAMESPACE b/NAMESPACE index 679fd04..282bb21 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/PlotRCPHistory.R b/R/PlotRCPHistory.R index a3354b1..0b8b820 100644 --- a/R/PlotRCPHistory.R +++ b/R/PlotRCPHistory.R @@ -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 @@ -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( @@ -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 { diff --git a/R/data.R b/R/data.R new file mode 100644 index 0000000..4957f70 --- /dev/null +++ b/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" diff --git a/data/fitBMWithShiftsToMammalData.rda b/data/fitBMWithShiftsToMammalData.rda new file mode 100644 index 0000000..24d7430 Binary files /dev/null and b/data/fitBMWithShiftsToMammalData.rda differ diff --git a/data/fitMappings_MGPM_B_best_clade_2_DataWithSEs.rda b/data/fitMappings_MGPM_B_best_clade_2_DataWithSEs.rda deleted file mode 100644 index f72d488..0000000 Binary files a/data/fitMappings_MGPM_B_best_clade_2_DataWithSEs.rda and /dev/null differ diff --git a/man/PlotRCPHistory.Rd b/man/PlotRCPHistory.Rd index d6bff84..ded49ba 100644 --- a/man/PlotRCPHistory.Rd +++ b/man/PlotRCPHistory.Rd @@ -14,7 +14,7 @@ PlotRCPHistory(fit, sizeGreyNodepoints = 2.2, \item{fit}{an object of S3 class `PCMFitModelMappings` returned by a call to `PCMFitMixed`.} -\item{sizeGreyNodepoints, sizeColorNodepoints, sizeBlackAllowedModelTypes, sizeColorAllowedModelTypes, sizeRankInQueue, vjustBlackAllowed, vjustColorAllowedModelTypes}{graphical parameters (see function description).} +\item{sizeGreyNodepoints, sizeColorNodepoints, sizeBlackAllowedModelTypes, sizeColorAllowedModelTypes, sizeRankInQueue, vjustBlackAllowedModelTypes, vjustColorAllowedModelTypes}{graphical parameters (see function description).} \item{...}{additional parameters passed to \code{\link{PCMTreePlot}}.} } @@ -39,7 +39,7 @@ on top showing: } \examples{ lstPlots <- PlotRCPHistory( - fitMappings_MGPM_B_best_clade_2_DataWithSEs, layout = "fan") + fitBMWithShiftsToMammalData, layout = "fan") cowplot::plot_grid(plotlist = lstPlots[!sapply(lstPlots, is.null)]) } diff --git a/man/fitBMWithShiftsToMammalData.Rd b/man/fitBMWithShiftsToMammalData.Rd new file mode 100644 index 0000000..1b5659f --- /dev/null +++ b/man/fitBMWithShiftsToMammalData.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{fitBMWithShiftsToMammalData} +\alias{fitBMWithShiftsToMammalData} +\title{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`.} +\usage{ +fitBMWithShiftsToMammalData +} +\description{ +An example model fit of BM model with shifts to a large phylogenetic tree +with bivariate trait data. +} +\keyword{datasets}