Chapter 6 annoSegment

This function can be used to add some segments annotations beside the plot or in plot.

Simple annotation:

library(jjAnno)
library(ggplot2)

# default plot
annoSegment(object = p,
            annoPos = 'top',
            xPosition = c(1:10))
## [1] "This palatte have 20 colors!"
## [1] "This palatte have 20 colors!"

Adjust rectWidth:

# adjust rectWidth
annoSegment(object = p,
            annoPos = 'top',
            xPosition = c(1:10),
            segWidth = 0.8)
## [1] "This palatte have 20 colors!"
## [1] "This palatte have 20 colors!"

Add segments with arrow:

library(ggplot2)

# add segments with arrow
annoSegment(object = p,
            annoPos = 'top',
            xPosition = c(1:10),
            segWidth = 0.9,
            lwd = 1,
            mArrow = arrow(ends = 'both',
                           length = unit(0.2,'cm'),
                           type = 'closed'))
## [1] "This palatte have 20 colors!"
## [1] "This palatte have 20 colors!"

Change rect color and fill:

# change rect color and fill
annoSegment(object = p,
            annoPos = 'top',
            xPosition = c(1:10),
            segWidth = 0.8,
            pCol = useMyCol('horizon',10))
## [1] "This palatte have 10 colors!"
## [1] "This palatte have 20 colors!"

Add segments with branch:

# add branch
annoSegment(object = p,
            annoPos = 'top',
            xPosition = c(1:10),
            segWidth = 0.8,
            addBranch = T,
            lwd = 4)
## [1] "This palatte have 20 colors!"
## [1] "This palatte have 20 colors!"

Change branch direction:

# change branch direction
annoSegment(object = p,
            annoPos = 'top',
            xPosition = c(1:10),
            segWidth = 0.8,
            addBranch = T,
            lwd = 4,
            branDirection = -1)
## [1] "This palatte have 20 colors!"
## [1] "This palatte have 20 colors!"

Add to botomn:

# add to botomn
annoSegment(object = p,
            annoPos = 'botomn',
            xPosition = c(1:10),
            segWidth = 0.8,
            addBranch = T,
            lwd = 4)
## [1] "This palatte have 20 colors!"
## [1] "This palatte have 20 colors!"

Add to right:

# add to right
annoSegment(object = p,
            annoPos = 'right',
            yPosition = c(1:10),
            segWidth = 0.8,
            addBranch = T,
            lwd = 4,
            branDirection = -1)
## [1] "This palatte have 20 colors!"
## [1] "This palatte have 20 colors!"

Add branch with arrow:

# add to botomn and make branch taged with arrow
annoSegment(object = p,
            annoPos = 'botomn',
            xPosition = c(1:10),
            segWidth = 0.8,
            addBranch = T,
            lwd = 3,
            bArrow = arrow(length = unit(0.2,'cm'),
                           ends = 'last'))
## [1] "This palatte have 20 colors!"
## [1] "This palatte have 20 colors!"

Add text label:

# add text label
annoSegment(object = p,
            annoPos = 'top',
            xPosition = c(1:10),
            segWidth = 0.8,
            addBranch = T,
            lwd = 4,
            branDirection = -1,
            addText = T,
            textLabel = paste0('anno',1:10,sep = ''),
            textRot = 0,
            textSize = 15)
## [1] "This palatte have 20 colors!"
## [1] "This palatte have 20 colors!"

Add text space relative to segments:

# add text space from segments
annoSegment(object = p,
            annoPos = 'top',
            xPosition = c(1:10),
            segWidth = 0.8,
            addBranch = T,
            lwd = 4,
            branDirection = -1,
            addText = T,
            textLabel = paste0('anno',1:10,sep = ''),
            textRot = 45,
            textSize = 15,
            textHVjust = 0.5)
## [1] "This palatte have 20 colors!"
## [1] "This palatte have 20 colors!"

Change text color:

# change text color
annoSegment(object = p,
            annoPos = 'top',
            xPosition = c(1:10),
            segWidth = 0.8,
            addBranch = T,
            lwd = 4,
            branDirection = -1,
            addText = T,
            textLabel = paste0('anno',1:10,sep = ''),
            textRot = 45,
            textSize = 15,
            textHVjust = 0.5,
            textCol = rep('grey50',10))
## [1] "This palatte have 20 colors!"

Change segments yPosition:

# change yPosition
annoSegment(object = p,
            annoPos = 'top',
            xPosition = c(1:10),
            segWidth = 0.8,
            pCol = useMyCol('horizon',10),
            yPosition = 5)
## [1] "This palatte have 10 colors!"
## [1] "This palatte have 20 colors!"

Supply your own coordinates to annotate:

# supply your own coordinates to annotate
annoSegment(object = p,
            annoPos = 'top',
            annoManual = T,
            xPosition = list(c(1,6),
                             c(5,10)),
            yPosition = 11,
            pCol = c('green','orange'))
## [1] "This palatte have 20 colors!"

Add branch to plot:

# add branch to plot
annoSegment(object = p,
            annoPos = 'top',
            annoManual = T,
            addBranch = T,
            lwd = 3,
            segWidth = 0.5,
            xPosition = list(c(1,6),
                             c(5,10)),
            yPosition = c(11,11),
            pCol = c('green','orange'),
            branDirection = -1)
## [1] "This palatte have 20 colors!"

Add to right:

# add to right
annoSegment(object = p,
            annoPos = 'right',
            yPosition = c(1:10),
            segWidth = 0.8)
## [1] "This palatte have 20 colors!"
## [1] "This palatte have 20 colors!"

Annotate GO plot with segments:

# annotate mannually
annoSegment(object = pgo,
            annoPos = 'left',
            annoManual = T,
            xPosition = rep(-0.15,3),
            yPosition = list(c(1,6,11),
                             c(5,10,15)),
            pCol = c('#F5F0BB','#C4DFAA','#90C8AC'),
            segWidth = 1)