diff --git a/R/mismatchplot.R b/R/mismatchplot.R index 9477c4a..e00f543 100644 --- a/R/mismatchplot.R +++ b/R/mismatchplot.R @@ -26,6 +26,10 @@ NULL #' @param inset the distance to the margin of the legend box (see the \code{\link{legend}} #' documentation) #' +#' @param view.legend if set to \code{FALSE} the legend corresponding to the groups is not dispayed. +#' +#' @param maxerror allows for specifying the maximum of errors to display on the graph. +#' #' @examples #' #' # Load the ROBITools library @@ -48,11 +52,14 @@ NULL #' @export mismatchplot = function(ecopcr,group=NULL, col=NULL,legend=NULL, - legend.cex=0.7,inset=c(0.02,0.02)) { + legend.cex=0.7,inset=c(0.02,0.02), + view.legend=TRUE, + maxerror=NA) { maxforward_error = max(ecopcr$forward_mismatch) maxreverse_error = max(ecopcr$reverse_mismatch) - maxerror=max(maxforward_error,maxreverse_error) + if (is.na(maxerror)) + maxerror=max(maxforward_error,maxreverse_error) if (is.null(group)) group=factor(rep("all",dim(ecopcr)[1])) @@ -65,7 +72,7 @@ mismatchplot = function(ecopcr,group=NULL, actualheight= maxerror + 1 actualwidth = maxerror + 1 - if (length(levels(group)) > 1) + if (length(levels(group)) > 1 & view.legend) actualwidth = actualwidth + 2 whitepaper(actualwidth,actualheight,xmin=-0.5,ymin=-0.5,asp=1) @@ -77,8 +84,8 @@ mismatchplot = function(ecopcr,group=NULL, labels=0:maxerror) - data = aggregate(group,by=list(forward=ecopcr$forward_mismatch, - reverse=ecopcr$reverse_mismatch), + data = aggregate(group,by=list(forward=factor(ecopcr$forward_mismatch,levels=0:maxerror), + reverse=factor(ecopcr$reverse_mismatch,levels=0:maxerror)), table) data <- data[rowSums(data[,c(-1,-2),drop=FALSE])>0, , drop=FALSE] @@ -89,8 +96,8 @@ mismatchplot = function(ecopcr,group=NULL, value=data[,c(-1,-2),drop=FALSE] - x = as.integer(data[,1]) - y = as.integer(data[,2]) + x = as.integer(data[,1]) - 1 + y = as.integer(data[,2]) - 1 diam = sqrt(rowSums(value)) radius = diam / max(diam) / 2 @@ -100,7 +107,7 @@ mismatchplot = function(ecopcr,group=NULL, label="",MoreArgs=list(col=col)) - if (length(levels(group)) > 1) + if ((length(levels(group))) > 1 & view.legend) legend('topright',legend=legend,fill=col, cex=legend.cex, inset=inset) } \ No newline at end of file