Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions R/SRCGrob.R
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 24 additions & 2 deletions R/create.ccf.densityplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
30 changes: 18 additions & 12 deletions R/set.up.plot.area.R
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down Expand Up @@ -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
);

Expand Down
2 changes: 0 additions & 2 deletions man/create.ccf.densityplot.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)}.}
Expand Down
Loading