diff --git a/R/SRCGrob.R b/R/SRCGrob.R index ad4f389..820a5d4 100644 --- a/R/SRCGrob.R +++ b/R/SRCGrob.R @@ -41,6 +41,10 @@ SRCGrob <- function( )); } + if ('CCF' %in% colnames(tree) && !('CP' %in% colnames(tree))) { + tree$CP <- tree$CCF; + } + add.node.text <- !is.null(node.text); add.polygons <- !is.null(tree$CP) && !disable.polygons; text.on.nodes <- FALSE; diff --git a/R/create.ccf.densityplot.R b/R/create.ccf.densityplot.R index c804fc1..70f2bc6 100644 --- a/R/create.ccf.densityplot.R +++ b/R/create.ccf.densityplot.R @@ -2,7 +2,6 @@ create.ccf.densityplot <- function( x, filename = NULL, clone.colours = NULL, - breaks = 100, xlab.label = 'CCF', ylab.label = 'SNV Density', xlimits = c(0, 1.5), @@ -93,7 +92,7 @@ create.ccf.densityplot <- function( abline.col = 'gray50', add.text = TRUE, text.labels = lapply(mean.ccf$CCF, round, 2), - text.x = mean.ccf$CCF, + text.x = spread.values(mean.ccf$CCF, min.dist = legend.title.cex / 10), text.y = ymax, text.fontface = 'bold', text.cex = legend.title.cex @@ -109,3 +108,26 @@ create.ccf.densityplot <- function( resolution = resolution )); } + + +spread.values <- function(x, min.dist = 0.1, max.iter = 10) { + x.out <- x; + for (iter in seq_len(max.iter)) { + changed <- FALSE; + ord <- order(x.out); + x.sorted <- x.out[ord]; + + for (i in 2:length(x.sorted)) { + gap <- x.sorted[i] - x.sorted[i - 1]; + if (gap < min.dist) { + shift <- (min.dist - gap) / 2; + x.sorted[i - 1] <- x.sorted[i - 1] - shift; + x.sorted[i] <- x.sorted[i] + shift; + changed <- TRUE; + } + } + x.out[ord] <- x.sorted; + if (!changed) break; + }; + return(x.out); +} diff --git a/R/set.up.plot.area.R b/R/set.up.plot.area.R index 07a48cb..fe89edc 100644 --- a/R/set.up.plot.area.R +++ b/R/set.up.plot.area.R @@ -86,12 +86,18 @@ extend.axis <- function(axisGrob, limits, type) { } add.axis.label <- function(axisGrob, axis.label, axis.position, axis.label.cex, vp) { + axis.cex <- axisGrob$gp$cex; if (axis.position == 'bottom') { d <- 'y'; just <- c('centre', 'top'); rot <- 0; x <- unit(0.5, 'npc'); - y <- (getGrob(axisGrob, 'labels')$y + getGrob(axisGrob, 'ticks')$y1) * 1.75; + + y <- unit( + convertY(getGrob(axisGrob, 'labels')$y, 'mm', valueOnly = TRUE) - + convertY(unit(1.2, 'lines') * axis.cex, 'mm', valueOnly = TRUE), + 'mm' + ); } else { pushViewport(vp); @@ -112,28 +118,28 @@ add.axis.label <- function(axisGrob, axis.label, axis.position, axis.label.cex, d <- 'x'; just <- c('centre', 'centre'); rot <- 90; - - x <- unit( - convertX(grobWidth(getGrob(axisGrob, 'labels')), 'mm', valueOnly = TRUE) * -(axisGrob$gp$cex) - - convertX(unit(1, 'lines') * axisGrob$gp$cex, 'mm', valueOnly = TRUE) + - convertX(getGrob(axisGrob, 'labels')$x * axisGrob$gp$cex, 'mm', valueOnly = TRUE), - 'mm' - ); + sign <- -1; } else if (axis.position == 'right') { d <- 'x'; just <- c('left', 'centre'); x <- (getGrob(axisGrob, 'labels')$x + tick.length) * 1.5; rot <- 270; + sign <- 1; } - popViewport() + x <- unit( + sign * ( + convertX(grobWidth(getGrob(axisGrob, 'labels')), 'mm', valueOnly = TRUE) * axis.cex + + convertX(unit(1, 'lines') * axis.cex, 'mm', valueOnly = TRUE) + ) + + convertX(getGrob(axisGrob, 'labels')$x, 'mm', valueOnly = TRUE), 'mm'); } axis.lab <- textGrob( name = 'axis.label', axis.label, gp = gpar(cex = axis.label.cex), - vjust = 0, + vjust = 1, x = x, rot = rot, y = y @@ -295,14 +301,14 @@ add.xaxis <- function( name = 'axis.content', at = xat, label = xlabels, - gp = gpar(cex = axis.label.cex), + gp = gpar(cex = axis.cex, vjust = 2), main = TRUE ); # Move the labels up slightly xaxis.labels <- editGrob( getGrob(xaxis, 'labels'), - y = unit(-0.09, 'npc'), + y = getGrob(xaxis, 'ticks')$y1 * 1.5, vjust = 1 ); diff --git a/man/create.ccf.densityplot.Rd b/man/create.ccf.densityplot.Rd index 30ff75d..9f7593d 100644 --- a/man/create.ccf.densityplot.Rd +++ b/man/create.ccf.densityplot.Rd @@ -9,7 +9,6 @@ create.ccf.densityplot( x, filename = NULL, clone.colours = NULL, - breaks = 100, xlab.label = 'CCF', ylab.label = 'SNV Density', xlimits = c(0, 1.5), @@ -30,7 +29,6 @@ create.ccf.densityplot( \item{x}{A data-frame with the following column names: 'SNV.id', 'clone.id', 'CCF'.} \item{filename}{Filename for tiff output, or if NULL returns the trellis object itself. Defaults to \code{NULL}.} \item{clone.colours}{Named list to provide a colour scheme for the clone ID covariate bar. If NULL, colours will be randomly generated. Defaults to \code{NULL}.} - \item{breaks}{Number of breaks for the histogram. Defaults to 100.} \item{xlab.label}{Defaults to \dQuote{CCF}.} \item{ylab.label}{Defaults to \dQuote{SNV Density}.} \item{xlimits}{Limits for the x-axis. Defaults to \code{c(0, 1.5)}.}