Skip to content

Commit 781cf26

Browse files
committed
Update to plot density by default
1 parent c675b6c commit 781cf26

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

R/chromDist.R

+29-25
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,49 @@
33
#' Plot genome-wide snv distribution
44
#' @import ggplot2
55
#' @keywords distribution
6+
#' @param snv_data A dataframe of snvs [Default: NULL]
7+
#' @param notch Filter in/out Notch region [Default: FALSE]
8+
#' @param write Write plot to file 'plots/snv_dist_genome_by.png'? [Default: FALSE]
9+
#' @param binsize Control the density adjustment if density=TRUE, or the binwidth if density=FALSE. For histograms a value of 0.1 corresponds to 1/10th of a Mb [Default:0.1]
10+
#' @param density Plot as density? [Default: TRUE]
611
#' @export
7-
8-
9-
chromDist <- function(..., snv_data=NULL, object=NA, notch=0, write=FALSE){
10-
if(missing(snv_data)){
11-
snv_data<-getData(...)
12-
}
13-
ext<-'.pdf'
14-
if(is.na(object)){
15-
object<-'grouped_trans'
16-
cols<-setCols(snv_data, "grouped_trans")
17-
}
18-
12+
chromDist <- function(..., snv_data=NULL, notch=FALSE, write=FALSE, binsize=0.1, density=TRUE){
1913
if(notch){
2014
snv_data<-exclude_notch(...)
21-
ext<-'_excl.N.pdf'
15+
ext<-'_excl.N.png'
16+
} else if(missing(snv_data)){
17+
snv_data<-getData(...)
2218
}
2319

24-
cat("Plotting snvs by", object, "\n")
20+
cols<-setCols(snv_data, "grouped_trans")
21+
blueBar <- '#3B8FC7'
22+
23+
cat("Plotting snv distribution across genome", "\n")
24+
25+
p <- ggplot(snv_data)
26+
if(density){
27+
p <- p + geom_density(aes(pos/1000000, fill=chrom), alpha = 0.6, adjust=binsize)
28+
p <- p + scale_y_continuous("Density", expand = c(0.01, 0.01))
2529

26-
p<-ggplot(snv_data)
27-
p<-p + geom_histogram(aes(pos/1000000, fill = get(object)), binwidth=0.1, alpha = 0.8)
30+
} else{
31+
p <- p + geom_histogram(aes(pos/1000000, fill=blueBar), binwidth=binsize, alpha = 0.8)
32+
p <- p + scale_y_continuous("Number of SNVs", expand = c(0.01, 0.01))
33+
p <- p + scale_fill_identity()
34+
}
35+
# p<-p + geom_histogram(aes(pos/1000000, fill = grouped_trans), binwidth=0.1, alpha = 0.8)
2836
p<-p + facet_wrap(~chrom, scale = "free_x", ncol = 2)
29-
p<-p + scale_x_continuous("Mbs", breaks = seq(0,33,by=1), limits = c(0, 33),expand = c(0.01, 0.01))
30-
p<-p + scale_y_continuous("Number of snvs", expand = c(0.01, 0.01))
37+
p<-p + scale_x_continuous("Genomic position (Mbs)", expand = c(0.01, 0.01))
3138
p<-p + cleanTheme() +
3239
theme(axis.text.x = element_text(angle = 45, hjust=1),
3340
axis.text = element_text(size=12),
3441
axis.title = element_text(size=20),
3542
strip.text.x = element_text(size = 15)
3643
)
37-
38-
if (object == 'grouped_trans'){
39-
p<-p + cols
40-
}
44+
# p <- p + cols
4145
if(write){
42-
chrom_outfile<-paste("snv_dist_genome_by_", object, ext, sep = "")
43-
cat("Writing file", chrom_outfile, "\n")
44-
ggsave(paste("plots/", chrom_outfile, sep=""), width = 20, height = 10)
46+
chrom_outfile<-"snv_dist_genome_by.png"
47+
cat("Writing file", paste0("plots/", chrom_outfile, "\n"))
48+
ggsave(paste0("plots/", chrom_outfile), width = 20, height = 10)
4549
}
4650
p
4751
}

man/chromDist.Rd

+13-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)