add a view.legend and a maxerror parameters to the mismatchplot function

This commit is contained in:
2016-05-23 15:54:44 +02:00
parent 27b72df0d1
commit c79ba4eac9

View File

@@ -26,6 +26,10 @@ NULL
#' @param inset the distance to the margin of the legend box (see the \code{\link{legend}} #' @param inset the distance to the margin of the legend box (see the \code{\link{legend}}
#' documentation) #' 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 #' @examples
#' #'
#' # Load the ROBITools library #' # Load the ROBITools library
@@ -48,11 +52,14 @@ NULL
#' @export #' @export
mismatchplot = function(ecopcr,group=NULL, mismatchplot = function(ecopcr,group=NULL,
col=NULL,legend=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) maxforward_error = max(ecopcr$forward_mismatch)
maxreverse_error = max(ecopcr$reverse_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)) if (is.null(group))
group=factor(rep("all",dim(ecopcr)[1])) group=factor(rep("all",dim(ecopcr)[1]))
@@ -65,7 +72,7 @@ mismatchplot = function(ecopcr,group=NULL,
actualheight= maxerror + 1 actualheight= maxerror + 1
actualwidth = maxerror + 1 actualwidth = maxerror + 1
if (length(levels(group)) > 1) if (length(levels(group)) > 1 & view.legend)
actualwidth = actualwidth + 2 actualwidth = actualwidth + 2
whitepaper(actualwidth,actualheight,xmin=-0.5,ymin=-0.5,asp=1) whitepaper(actualwidth,actualheight,xmin=-0.5,ymin=-0.5,asp=1)
@@ -77,8 +84,8 @@ mismatchplot = function(ecopcr,group=NULL,
labels=0:maxerror) labels=0:maxerror)
data = aggregate(group,by=list(forward=ecopcr$forward_mismatch, data = aggregate(group,by=list(forward=factor(ecopcr$forward_mismatch,levels=0:maxerror),
reverse=ecopcr$reverse_mismatch), reverse=factor(ecopcr$reverse_mismatch,levels=0:maxerror)),
table) table)
data <- data[rowSums(data[,c(-1,-2),drop=FALSE])>0, , drop=FALSE] 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] value=data[,c(-1,-2),drop=FALSE]
x = as.integer(data[,1]) x = as.integer(data[,1]) - 1
y = as.integer(data[,2]) y = as.integer(data[,2]) - 1
diam = sqrt(rowSums(value)) diam = sqrt(rowSums(value))
radius = diam / max(diam) / 2 radius = diam / max(diam) / 2
@@ -100,7 +107,7 @@ mismatchplot = function(ecopcr,group=NULL,
label="",MoreArgs=list(col=col)) 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) legend('topright',legend=legend,fill=col, cex=legend.cex, inset=inset)
} }