R/qtlcharts is an R package to create interactive charts for QTL data, for use with R/qtl. While its interactive QTL charts are particularly useful for exploratory data analysis within R, they may also be included within R Markdown-based reports.

R Markdown is a extension of Markdown, using knitr, to write simply-marked-up text, with chunks of R code, that is converted to an html file, for viewing in a web browser. The chunks of code are processed by knitr and replaced with the results or graphs produced.

For more information on R Markdown and knitr, see the knitr in a knutshell tutorial.

To include R/qtlcharts-based interactive charts within an R Markdown document, you just need to include the relevant calls to the R function within a code chunk.

I’m going to use defaults of fig.width=8 and fig.height=6 for each of these charts. (But note that iplotRF and iplotScantwo ignore these settings.)

knitr::opts_chunk$set(fig.width=8, fig.height=6, message=FALSE)

An example

As an example, we’ll consider the grav dataset included with R/qtlcharts. These are data from Moore et al. Genetics 195:1077-1086, 2013, on a QTL experiment on gravitropism in Arabidopsis, with data on 162 recombinant inbred lines (Ler × Cvi). Seedlings were sprouted and then rotated 90 degrees with respect to gravity; the growth of the seedlings was then recorded on video. The outcome is the root tip angle (in degrees) at two-minute increments over eight hours.

We’ll first load the R/qtl and R/qtlcharts packages and the data set.

library(qtl)
library(qtlcharts)
data(grav)

For this illustration, we’ll reduce the size of the data set, by retaining only every 5th phenotype value.

grav$pheno <- grav$pheno[,seq(1, nphe(grav), by=5)]

The times at which the measurements were made are recorded (in minutes) in the phenotype names. We’ll grab those times and convert them to hours.

times <- as.numeric(sub("T", "", phenames(grav)))/60

Let’s further run a single-QTL genome scan with each individual time point, using Haley-Knott regression.

grav <- calc.genoprob(grav, step=1)
out.hk <- scanone(grav, pheno.col=1:nphe(grav), method="hk")

Now, the charts

First, let’s make an interactive chart of the genetic map of markers for these data, just because it’s easy. iplotMap will take either a map object or the cross object grav; in the latter case, it uses the R/qtl function pull.map to pull out the map.

iplotMap(grav)

Now, let’s use iplotCorr to plot a heat map of the correlation matrix for the phenotype at all pairs of times, linked to scatterplots of the phenotypes. (Note that for this plot, I’m using fig.height=4.2 in order to avoid some empty space below the figure.)

iplotCorr(grav$pheno)

Next, let’s use plotCurves to create an interactive plot of the phenotype traces, linked to scatterplots of two cross-sections. We use chartOpts to specify the axis labels.

iplotCurves(grav$pheno, times,
            grav$pheno[,c("T30", "T240")],
            grav$pheno[,c("T240", "T480")],
            chartOpts=list(curves_xlab="Time", curves_ylab="Root tip angle",
                           scat1_xlab="Angle at 30 min", scat1_ylab="Angle at 4 hrs",
                           scat2_xlab="Angle at 4 hrs", scat2_ylab="Angle at 8 hrs"))

Finally, iplotMScanone produces a heat map of the LOD scores for each individual time point at each genomic position, linked to the individual LOD curves and to a plot of the estimated QTL effect over time.

iplotMScanone(out.hk, grav, chartOpts=list(eff_ylab="QTL effect"))

Charts within a loop

If you want to produce multiple interactive charts within a loop, you need to finesse it a bit with tags and tagList from the htmltools package.

Create a list containing the charts, wrap each within a <p> tag using tags$p(), and then use tagList when you print the list.

times <- c("T30", "T240", "T480")
times_number <- match(times, phenames(grav))
plot_list <- vector("list", length(times))
for(i in seq(along=times))
    plot_list[[i]] <- iplotScanone(out.hk, lodcolumn=times_number[i])
plot_list <- lapply(plot_list, htmltools::tags$p)
htmltools::tagList(plot_list)