-
Notifications
You must be signed in to change notification settings - Fork 25
/
plot_CCF_histogram.R
56 lines (52 loc) · 1.48 KB
/
plot_CCF_histogram.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#' Plot the data histogram for a patient.
#'
#' @description
#'
#' If this cohort is working with CCF data, this function plots
#' the CCF histogram of each one of the samples available for
#' a patient, facetting the sample variable.
#'
#' Otherwise, this plot does not make much sense.
#'
#' @param x A REVOLVER cohort object.
#' @param patient The id of a patient.
#'
#' @return A \code{ggplot} plot.
#'
#' @family Plotting functions
#'
#' @export
#'
#' @examples
#' # Data released in the 'evoverse.datasets'
#' data('TRACERx_NEJM_2017_REVOLVER', package = 'evoverse.datasets')
#'
#' plot_patient_CCF_histogram(TRACERx_NEJM_2017_REVOLVER, 'CRUK0001')
#'
#' plot_patient_CCF_histogram(TRACERx_NEJM_2017_REVOLVER, 'CRUK0002')
plot_patient_CCF_histogram = function(x, patient)
{
# Samples and CCF are all we use to make this plot
samples = Samples(x, patient)
values = Data(x, patient) %>%
select(!!samples, id, cluster, is.clonal)
# Melt everything and make the first plot
CCF_values = values %>%
select(!!samples, id, cluster) %>%
reshape2::melt(id = c('id', 'cluster'))
# Clusters
Cluster_values = values %>%
select(cluster, id) %>%
reshape2::melt(id = 'id')
ncluster = length(unique(Cluster_values$value))
ggplot(CCF_values %>%
filter(value > 0), aes(value)) +
geom_histogram(binwidth = 0.01) +
facet_wrap(~variable) +
my_ggplot_theme() +
labs(
title = "Data histogram",
x = 'CCF',
y = 'Observations'
)
}