Commit c79ba4ea by Eric Coissac

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

parent 27b72df0
Pipeline #2 skipped
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment