Skip to content

Instantly share code, notes, and snippets.

@kbroman
Last active June 18, 2020 16:52
Show Gist options
  • Save kbroman/23a81082010dbea2788c72c6d16121fd to your computer and use it in GitHub Desktop.
Save kbroman/23a81082010dbea2788c72c6d16121fd to your computer and use it in GitHub Desktop.
color scale for R/qtl plotRF()
library(qtl)
# example data set; calculate pairwise rec fracs
data(hyper)
hyper <- est.rf(hyper)
# set up color scale
n_colors <- 256
zmax <- 12
lod <- seq(0, zmax, len=n_colors)
# values for axis
lod_scale <- pretty(lod, n=8)
# values for axis, in rec fracs
rf_scale <- c(0.07, 0.08, 0.09, pretty(seq(0, 0.5, len=8))[-1])
rf_scale_at <- -4*(log2(rf_scale) + 1)/12*zmax
# make the plot in a PNG file
png("plotrf_colorscale.png", height=750, width=1000, pointsize=12)
# layout to make side-by-side figures with different widths
layout(cbind(1,2), width=c(10,3))
# recombination fraction plot
plotRF(hyper)
# color scale plot
par(mar=c(5.1, 5.1, 4.1, 5.1))
image(1, lod, rbind(lod), col=qtl:::viridis_qtl(n_colors),
xaxt="n", xlab="", ylab="", yaxt="n")
axis(side=4, at=lod_scale, las=1)
axis(side=2, at=rf_scale_at, labels=rf_scale, las=1)
mtext(side=2, "rec. frac", line=3)
mtext(side=4, "LOD score", line=2.5)
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment