diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2018-03-27 20:01:24 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2018-03-27 20:01:24 +0100 |
| commit | 9207c460b56f176fa08f610276f80a4150331243 (patch) | |
| tree | 1037c554b8ddf6c69930e2c3bcb8206c4a0104d6 /R | |
| parent | update submodule (diff) | |
| download | rgensvm-9207c460b56f176fa08f610276f80a4150331243.tar.gz rgensvm-9207c460b56f176fa08f610276f80a4150331243.zip | |
allow user to override plot limits
Diffstat (limited to 'R')
| -rw-r--r-- | R/plot.gensvm.R | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/R/plot.gensvm.R b/R/plot.gensvm.R index 85ff3b5..cbad9f0 100644 --- a/R/plot.gensvm.R +++ b/R/plot.gensvm.R @@ -15,6 +15,11 @@ #' @param with.legend show the legend for the class labels #' @param center.plot ensure that the boundaries and margins are always visible #' in the plot +#' @param xlim allows the user to force certain plot limits. If set, these +#' bounds will be used for the horizontal axis. +#' @param ylim allows the user to force certain plot limits. If set, these +#' bounds will be used for the vertical axis and the value of center.plot will +#' be ignored #' @param ... further arguments are ignored #' #' @return returns the object passed as input @@ -52,7 +57,7 @@ #' plot.gensvm <- function(fit, x, y.true=NULL, with.margins=TRUE, with.shading=TRUE, with.legend=TRUE, center.plot=TRUE, - ...) + xlim=NULL, ylim=NULL, ...) { if (fit$n.classes != 3) { cat("Error: Can only plot with 3 classes\n") @@ -74,7 +79,8 @@ plot.gensvm <- function(fit, x, y.true=NULL, with.margins=TRUE, return } if (!is.null(x.train) && ncol(x.train) != fit$n.features) { - cat("Error: Number of features of fitted model and training data disagree.") + cat("Error: Number of features of fitted model and training data ", + "disagree.\n", sep="") return } @@ -136,13 +142,15 @@ plot.gensvm <- function(fit, x, y.true=NULL, with.margins=TRUE, par(pty="s") if (center.plot) { - new.xlim <- c(min(min(S[, 1]), -1.2), max(max(S[, 1]), 1.2)) - new.ylim <- c(min(min(S[, 2]), -0.75), max(max(S[, 2]), 1.2)) + if (is.null(xlim)) + xlim <- c(min(min(S[, 1]), -1.2), max(max(S[, 1]), 1.2)) + if (is.null(ylim)) + ylim <- c(min(min(S[, 2]), -0.75), max(max(S[, 2]), 1.2)) plot(S[, 1], S[, 2], col=col.vector, pch=mark.vector, ylab='', xlab='', - asp=1, xlim=new.xlim, ylim=new.ylim) + asp=1, xlim=xlim, ylim=ylim) } else { - plot(S[, 1], S[, 2], col=col.vector, pch=mark.vector, ylab='', xlab='', - asp=1) + plot(S[, 1], S[, 2], col=col.vector, pch=mark.vector, ylab='', + xlab='', asp=1, xlim=xlim, ylim=ylim) } limits <- par("usr") |
