Skip to content

Commit

Permalink
add annotation for sample
Browse files Browse the repository at this point in the history
  • Loading branch information
junjunlab committed Sep 20, 2022
1 parent af5703e commit c9eceec
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Imports:
rtracklayer,
ggnewscale,
future,
furrr
furrr,
ggh4x
Depends:
R (>= 2.10),
tidyverse
Expand Down
50 changes: 43 additions & 7 deletions R/trackVis.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
#' @param label.text.size the new label text size, default(5).
#' @param label.hjust the new label text hjust, default(1).
#' @param yinfo.hjust the new style Y axis text hjust, default(0).
#' @param facetGroup the annotation for samples, default(NULL).
#' @param annoLine.size the annotation line size, default(1).
#' @param line.arrow the annotation line arrow, default(NULL).
#'
#' @return a ggplot object.
#' @export
Expand All @@ -69,6 +72,9 @@ trackVis <- function(bWData = NULL,
sampleName.dist = 0,
sampleName.hjust = 1,
sampleName.vjust = 0.5,
facetGroup = NULL,
annoLine.size = 1,
line.arrow = NULL,
y.max = NULL,
xAxis.info = TRUE,
yAxis.info = TRUE,
Expand Down Expand Up @@ -136,11 +142,22 @@ trackVis <- function(bWData = NULL,
size = 1) +
ggplot2::xlab('') + ggplot2::ylab('') +
ggplot2::coord_cartesian(expand = 0) +
ggplot2::facet_wrap(~fileName,ncol = ncol,
strip.position = 'left',scales = scales) +
ggplot2::guides(fill = ggplot2::guide_legend(title = '')) +
ggplot2::guides(color = ggplot2::guide_legend(title = ''))

if(is.null(facetGroup)){
p1 <- p1 +
ggplot2::facet_wrap(~fileName,ncol = ncol,
strip.position = 'left',scales = scales)
}else{
p1 <- p1 +
ggh4x::facet_nested_wrap(facets = c(facetGroup,"fileName"),
nest_line = ggplot2::element_line(colour = 'black',
size = annoLine.size,
arrow = line.arrow),
strip.position = 'left',
scales = scales,ncol = ncol)
}
# y labels
if(is.null(y.max)){
ylimit <- range(regeion.bw$score)[2]
Expand Down Expand Up @@ -264,9 +281,22 @@ trackVis <- function(bWData = NULL,

# whether add new sample label
if(new.label == TRUE){
labelinfo <- data.frame(fileName = unique(regeion.bw$fileName),
x = range(regeion.bw$start)[1] + pos.label.ratio[1]*(range(regeion.bw$start)[2] - range(regeion.bw$start)[1]),
y = pos.label.ratio[2]*ylimit)
if(is.null(facetGroup)){
group <- NA
fileName <- unique(regeion.bw$fileName)
}else{
tmp <- regeion.bw %>%
dplyr::select(fileName,group) %>%
unique()
fileName <- tmp$fileName
group <- tmp$group
}

# label info
labelinfo <- data.frame(fileName = fileName,
group = group,
x = range(regeion.bw$start)[1] + pos.label.ratio[1]*(range(regeion.bw$start)[2] - range(regeion.bw$start)[1]),
y = pos.label.ratio[2]*ylimit)

# add text label
if(is.null(label.color)){
Expand All @@ -284,8 +314,14 @@ trackVis <- function(bWData = NULL,
size = label.text.size,
hjust = label.hjust,
fontface = label.face) +
ggplot2::scale_color_manual(values = label.color) +
ggplot2::theme(strip.text.y.left = ggplot2::element_blank())
ggplot2::scale_color_manual(values = label.color)
# ggplot2::theme(strip.text.y.left = ggplot2::element_blank())
if(is.null(facetGroup)){
p7 <- p7 +
ggplot2::theme(strip.text.y.left = ggplot2::element_blank())
}else{
p7 <- p7
}
}else{
p7 <- p6
}
Expand Down
6 changes: 6 additions & 0 deletions man/trackVis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c9eceec

Please sign in to comment.