Learn R Programming

GenoView (version 1.6.0)

plotExonRect: Plot Rectangular Exon Components

Description

Adds colored rectangular blocks, denoting exon components such as coding sequences or untranslated regions, to a ggplot. Provides filtering to highlight a subset of the input data in the plot.

Usage

plotExonRect(plt, component = c("cds", "utr"), comp.df, col.name = "type", filt.by.comp = FALSE, size = c(0.4, 0.15), subset.df, comp.col = "dark grey", sub.col = RColorBrewer::brewer.pal(3, "Set1")[2], aesCst)

Arguments

plt
A ggplot object
component
Exon component string, such as "cds", "utr"
comp.df
Exon components data.frame, contains a col.name column which contains exon component strings and columns for start, end, and stepping (starting y position in plot)
col.name
Column name used to filter comp.df before plotting
filt.by.comp
Determines if comp.df should be filtered for component contents before plotting
size
Half the height of the rectangular blocks
subset.df
Secondary data.frame, contains a col.name column which contains exon component strings and columns for start, end, and stepping (starting y position in plot). This data is plotted in a highlighting colour.
comp.col
Colour of data in code.df
sub.col
Highlighting colour of data in subset.df
aesCst
Custom aes function which can handle constants in variables

Value

ggplot object with additional geom_rect() layers

Examples

Run this code
library(ggplot2)

set.seed(3)
N = 30
# Create sample base exon components
starts = sample(1:10000, size = N, replace = TRUE)
sample.df <- data.frame(start = starts, 
                        end = starts + sample(100:500, size = N), 
                        stepping = 1, 
                        type = sample(c("cds", "utr", "gap"), 
                                        size = N, replace = TRUE))

# Create sample highlighted exon components
N = 5
starts = sample(1:10000, size = N, replace = TRUE)
sample.sub <- data.frame(start = starts, 
                        end = starts + sample(100:500, size = N), 
                        stepping = 1, 
                        type = sample(c("cds", "utr", "gap"), 
                                        size = N, replace = TRUE))

# Using an aes function which evaluates arguments locally without parsing
aesCst <- function(...) {
    structure(list(...),  class = "uneval")
}

step1 <-ggplot() + 
        geom_abline(intercept = 1, slope = 0, 
                    aes(xmin = -1, xmax = 1, ymin = 0.5, ymax = 1.5), 
                    color = "dark grey")
                    
step2 <- plotExonRect(plt = step1, component = "cds", comp.df = sample.df, 
                        filt.by.comp = TRUE, size = 0.4, subset.df = sample.sub, 
                        aesCst = aesCst)
plotExonRect(plt = step2, component = "utr", comp.df = sample.df, 
                        filt.by.comp = TRUE, size = 0.15, subset.df = sample.sub, 
                        aesCst = aesCst)

Run the code above in your browser using DataLab