-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add autoplot function for ecr result object
- Loading branch information
1 parent
8ce157c
commit 5ee4238
Showing
6 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#' Plot optimization trace. | ||
#' | ||
#' @param object [\code{ecr_result}]\cr | ||
#' ecr result object. | ||
#' @param xlim [\code{numeric(2)} | NULL]\cr | ||
#' Lower and upper bound for generation. If \code{NULL}, this is set automatically. | ||
#' @param ylim [\code{numeric(2)} | NULL]\cr | ||
#' Lower and upper bound for fitness. If \code{NULL}, this is set automatically. | ||
#' @param ... [any]\cr | ||
#' Not used. | ||
#' @return [\code{\link[ggplot2]{ggplot}}] | ||
#' @export | ||
autoplot.ecr_result = function(object, xlim = NULL, ylim = NULL, ...) { | ||
ggdf = as.data.frame(object$opt.path) | ||
ggdf = ggdf[c("dob", "pop.min.fitness", "pop.mean.fitness", "pop.median.fitness", "pop.max.fitness")] | ||
|
||
xlim = BBmisc::coalesce(xlim, c(0, max(ggdf$dob))) | ||
ylim = BBmisc::coalesce(ylim, c(0, max(ggdf$pop.max.fitness))) | ||
assertNumeric(ylim, len = 2L, any.missing = FALSE) | ||
assertNumeric(xlim, len = 2L, any.missing = FALSE) | ||
|
||
requirePackages("reshape2", why = "ecr") | ||
ggdf = melt(ggdf, c("dob")) | ||
ggdf$variable = as.factor(ggdf$variable) | ||
|
||
pl = ggplot(data = ggdf, mapping = aes_string(x = "dob", y = "value", linetype = "variable")) | ||
pl = pl + geom_line() | ||
pl = pl + xlab("Generation") + ylab("Fitness") | ||
pl = pl + xlim(xlim) + ylim(ylim) | ||
pl = pl + scale_linetype_discrete(name = "Type") | ||
pl = pl + ggtitle(sprintf("Optimization trace for function '%s'", getName(object$objective.fun))) | ||
|
||
return(pl) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
#' @import ggplot2 | ||
#' @import checkmate | ||
#' @import parallelMap | ||
#' @import reshape2 | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
% Generated by roxygen2 (4.1.0): do not edit by hand | ||
% Please edit documentation in R/autoplotECRResult.R | ||
\name{autoplot.ecr_result} | ||
\alias{autoplot.ecr_result} | ||
\title{Plot optimization trace.} | ||
\usage{ | ||
\method{autoplot}{ecr_result}(object, xlim = NULL, ylim = NULL, ...) | ||
} | ||
\arguments{ | ||
\item{object}{[\code{ecr_result}]\cr | ||
ecr result object.} | ||
|
||
\item{xlim}{[\code{numeric(2)} | NULL]\cr | ||
Lower and upper bound for generation. If \code{NULL}, this is set automatically.} | ||
|
||
\item{ylim}{[\code{numeric(2)} | NULL]\cr | ||
Lower and upper bound for fitness. If \code{NULL}, this is set automatically.} | ||
|
||
\item{...}{[any]\cr | ||
Not used.} | ||
} | ||
\value{ | ||
[\code{\link[ggplot2]{ggplot}}] | ||
} | ||
\description{ | ||
Plot optimization trace. | ||
} | ||
|