Skip to content

Commit 906319e

Browse files
authored
Merge pull request #187 from uclahs-cds/selinawu-fix-clone-densityplot-factors
Set clone ID factor levels for consistent plotting
2 parents 4c04296 + c0444c3 commit 906319e

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

R/create.ccf.densityplot.R

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ create.ccf.densityplot <- function(
1919
...
2020
) {
2121

22+
x$clone.id <- factor(x$clone.id);
23+
2224
if (is.null(clone.colours)) {
2325
clone.colours <- get.colours(x$clone.id, return.names = TRUE);
2426
}
27+
clone.colours <- clone.colours[as.character(sort(unique(x$clone.id)))];
2528

2629
mean.ccf <- aggregate(CCF ~ clone.id, data = x, FUN = mean);
2730
nsnv <- aggregate(SNV.id ~ clone.id, data = x, FUN = length);
@@ -38,16 +41,19 @@ create.ccf.densityplot <- function(
3841
density.df <- do.call(rbind, density.list);
3942
density.df$y <- density.df$y * (nsnv$SNV.id[match(density.df$clone.id, nsnv$clone.id)] / nrow(x));
4043

41-
legend.label <- sapply(names(clone.colours), function(k) {
42-
nsnv <- nsnv[nsnv$clone.id == k, ]$SNV.id;
43-
return(paste0(k, ' (', nsnv, ')'));
44+
clones.to.plot <- sort(intersect(names(clone.colours), nsnv$clone.id));
45+
legend.label <- sapply(clones.to.plot, function(k) {
46+
nsnv.count <- nsnv[nsnv$clone.id == k, ]$SNV.id;
47+
return(paste0(k, ' (', nsnv.count, ')'));
4448
});
49+
legend.colours <- clone.colours[clones.to.plot];
50+
4551
clone.legend <- BoutrosLab.plotting.general::legend.grob(
4652
list(
4753
legend = list(
4854
title = 'Clone (SNVs)',
49-
labels = legend.label[names(clone.colours)],
50-
colours = c(clone.colours),
55+
labels = legend.label,
56+
colours = legend.colours,
5157
border = 'black'
5258
)
5359
),
@@ -70,6 +76,7 @@ create.ccf.densityplot <- function(
7076
xlimits = xlimits,
7177
xat = xat,
7278
ylimits = c(-0.05, 1.05) * ymax,
79+
breaks = breaks,
7380
legend = list(inside = list(
7481
fun = clone.legend,
7582
x = legend.x,

0 commit comments

Comments
 (0)