Publications by mrtnj
Using R: From gather to pivot
Since version 1.0.0, released in September, the tidyr package has a new replacement for the gather/spread pair of functions, called pivot_longer/pivot_wider. (See the blog post about the release. It can do a lot of cool things.) Just what we needed, another pair of names for melt/cast, right? Yes, I feel like this might just be what we need! My j...
2826 sym R (1739 sym/6 pcs)
Using R: Installing GenABEL and RepeatABEL
GenABEL is an R package for performing genome-wide association with linear mixed models and a genomic relationship matrix. RepeatABEL is a package for such genome-wide association studies that also need repeated measures. Unfortunately, since 2018, GenABEL is not available on CRAN anymore, because of failed checks that were not fixed. (Checks ar...
3704 sym R (440 sym/3 pcs)
Using R: Animal model with hglm and Stan (with Cholesky trick)
A few weeks ago I posted about fitting the quantitative genetic animal model with MCMCglmm and R-INLA. Since then, I listened to a talk by Lars Rönnegård, one of the creators of the hglm package, and this paper was published in GSE about animal models in Stan. hglm The hglm package fits hierarchical generalised linear models. That includes the ...
5558 sym R (1481 sym/7 pcs) 10 img
Using R: from plyr to purrr, part 0 out of however many
This post is me thinking out loud about applying functions to vectors or lists and getting data frames back. Using R is an ongoing process of finding nice ways to throw data frames, lists and model objects around. While tidyr has arrived at a comfortable way to reshape dataframes with pivot_longer and pivot_wider, I don’t always find the replac...
2240 sym R (312 sym/3 pcs)
Using R: 10 years with R
Yesterday, 29 Feburary 2020, was the 20th anniversary of the release R 1.0.0. Jozef Hajnala’s blog has a cute anniversary post with some trivia. I realised that it is also (not to the day, but to the year) my R anniversary. Today is the 20th anniversary of the release of R 1.0.0. pic.twitter.com/gwItCBGYV4 — The R Foundation (@_R_Foundation)...
5057 sym R (80 sym/1 pcs)
Using R: simple Gantt chart with ggplot2
Jeremy Yoder’s code for a simple Gantt chart on the Molecular Ecologist blog uses geom_line and gather to prepare the data structure. I like using geom_linerange and a coord_flip, which lets you use start and end columns directly without pivoting. Here is a very serious data frame of activities: # A tibble: 6 x 4 activity category ...
729 sym R (1350 sym/2 pcs) 2 img
Using R: setting a colour scheme in ggplot2
Note to self: How to quickly set a colour scheme in ggplot2. Imagine we have a series of plots that all need a uniform colour scale. The same category needs to have the same colour in all graphics, made possibly with different packages and by different people. Instead of hard-coding the colours and the order of categories, we can put them in a fi...
874 sym R (761 sym/3 pcs) 4 img
Twin lambs with different fathers
I just learned that in sheep, lambs from the same litter pretty often have different fathers, if the ewe has mated with different males. Berry et al. (2020) looked at sheep flocks on Irland that used more than one ram, and: Of the 539 pairs of twins included in the analysis, 160 (i.e. 30%) were sired by two different rams. Of the 137 sets of trip...
5273 sym R (1957 sym/3 pcs) 4 img
A model of polygenic adaptation in an infinite population
How do allele frequencies change in response to selection? Answers to that question include ”it depends”, ”we don’t know”, ”sometimes a lot, sometimes a little”, and ”according to a nonlinear differential equation that actually doesn’t look too horrendous if you squint a little”. Let’s look at a model of the polygenic adapta...
7534 sym R (675 sym/3 pcs) 52 img
A genetic mapping animation in R
Cullen Roth posted a beautiful animation of quantitative trait locus mapping on Twitter. It is pretty amazing. I wanted to try to make something similar in R with gganimate. It’s not going to be as beautiful as Roth’s animation, but it will use the same main idea of showing both a test statistic along the genome, and the underlying genotypes ...
4277 sym R (3410 sym/6 pcs) 6 img