5454# '
5555# ' @param xAxis.info Whether retain X axis ticks and text, default(TRUE).
5656# ' @param reverse.y whether reverse the Y axis, default(FALSE).
57+ # ' @param text.pos the label position(left/right), default(middle).
5758# '
5859# ' @import tidyverse
5960# ' @import cowplot
@@ -181,6 +182,7 @@ trancriptVis <- function(gtfFile = NULL,
181182 speArrowLen = 0.1 ,
182183 speArrowType = " closed" ,
183184 textLabel = ' transcript_id' ,
185+ text.pos = " middle" ,
184186 textLabelSize = 5 ,
185187 textLabelColor = ' black' ,
186188 base_size = 14 ,
@@ -349,12 +351,37 @@ trancriptVis <- function(gtfFile = NULL,
349351
350352 # add text x/y pos
351353 if (revNegStrand == FALSE ){
352- trans $ textX <- ifelse(trans $ strand == ' +' ,trans $ start + trans $ width / 2 ,
353- trans $ end - trans $ width / 2 )
354- trans $ textY <- trans $ yPos + relTextDist
354+ # define label position
355+ if (text.pos == " left" ){
356+ text.pos.hjust = 1
357+ trans $ textX <- trans $ start
358+ trans $ textY <- trans $ yPos + relTextDist
359+ }else if (text.pos == " right" ){
360+ text.pos.hjust = 0
361+ trans $ textX <- trans $ end
362+ trans $ textY <- trans $ yPos + relTextDist
363+ }else {
364+ text.pos.hjust = 0.5
365+ trans $ textX <- ifelse(trans $ strand == ' +' ,
366+ trans $ start + trans $ width / 2 ,
367+ trans $ end - trans $ width / 2 )
368+ trans $ textY <- trans $ yPos + relTextDist
369+ }
355370 }else {
356- trans $ textX <- (trans $ start + trans $ end )/ 2
357- trans $ textY <- trans $ yPos + relTextDist
371+ # define label position
372+ if (text.pos == " left" ){
373+ text.pos.hjust = 1
374+ trans $ textX <- trans $ start
375+ trans $ textY <- trans $ yPos + relTextDist
376+ }else if (text.pos == " right" ){
377+ text.pos.hjust = 0
378+ trans $ textX <- trans $ end
379+ trans $ textY <- trans $ yPos + relTextDist
380+ }else {
381+ text.pos.hjust = 0.5
382+ trans $ textX <- (trans $ start + trans $ end )/ 2
383+ trans $ textY <- trans $ yPos + relTextDist
384+ }
358385 }
359386
360387 # #############################################################################
@@ -599,6 +626,7 @@ trancriptVis <- function(gtfFile = NULL,
599626 label = textLabel ),
600627 size = textLabelSize ,
601628 color = textLabelColor ,
629+ hjust = text.pos.hjust ,
602630 check_overlap = T ) +
603631 ggplot2 :: theme_bw(base_size = base_size ) +
604632 ggplot2 :: theme(panel.grid = ggplot2 :: element_blank(),
@@ -614,6 +642,7 @@ trancriptVis <- function(gtfFile = NULL,
614642 ggplot2 :: aes_string(x = " textX" ,y = " textY" ,label = textLabel ),
615643 size = textLabelSize ,
616644 color = textLabelColor ,
645+ hjust = text.pos.hjust ,
617646 text_only = text_only ) +
618647 ggplot2 :: coord_polar(theta = ' x' ,start = cicStart ) +
619648 ggplot2 :: scale_y_continuous(limits = c(ylimLow ,nrow(arrow_trans ) + 1 )) +
0 commit comments