R for Biologists

Getting around the excellent programming language R.

R
tutorial
Author

Brady Johnston

Published

July 7, 2020

A couple of months ago I ran (with lots of help for content) an R for biologists workshop.

It was aimed at wet lab biologists and biochemists who hadn’t done much coding before. R is a fantastic language for doing statistical analysis, making beautiful graphics and visualising very complex datasets. I highly recommend it. A lot of people say the syntax is quirky (it is) but once you get the hang of it, you won’t regret.

The original working document for the tuturial was here, but I thought I might just include all of it directly on my blog as it was all written in markdown anyway.

Below is the contents of the workshop, along with video recordings of the sessions:

R for Biologists Workshop

This document will contain relevant links, information, and allow us to quickly and collaboratively share code with good formatting.

Brady’s Twitter: @bradyajohnston

Zoom Info

  • Zoom link: https://uwa.zoom.us/j/94747101358?pwd=V0NqQ1dJaW1sU0J5ZVIyV0Rta0huQT09
  • Zoom password: 546735

Course outline and info:

Web outline here

Download all files here:

Rstudio Cheat sheet

Markdown cheat sheet

Anonymous Feedback form:

https://forms.gle/7uuEMs47SuK5Nsm56

Session recordings:

If any of these don’t work, send me an email. Session: 1. Recording, Password: 6eTQkyMH-qga 1. Recording, Password: Vs7hmZ7qU2-Y 1. Recording, Password: Brp7CL+HLtRS 1. Recording, Password: xJpHoC!h3V2d 1. Recording, Password: GaFdz4!uznE2 2. Recording, Password: Sf=6eALB6uMB 3. Recording, Password: zdZpyda8*ctg 4. Recording, Password: 7PfQkM2wU@SH 5. Recording: Password: -gmkneK4TnBU

Introductions:

Use this space to introduce yourself! Just a brief bio about research you do, coding experience you might have etc.

Hello, I’m Soodeh

Hey guys, Heidar here Hi I am Federica from Milan, Italy :)

Hi Brady, thanks for the workshop! Kalia

I am Paula (Pau VT), from Germany, but originally from Chile

Hello!

Hello! My name is Brady, and I am from Perth, australia. It is nice to have you all here!

Hello Brady

Hi everyone, this is Sam, I’m from Perth WA.

Hello all! I’m Callum and I’m from Perth Aus!

Hello, my name is Ayeisha and I am also from Perth, Australia.

Hello, My name is Khyati and am from India.

G’day, my name is James, currently in Perth.

Hello, my name is Alessio and I am from Lombardy, Italy

Hello! I’m Jacob - from Perth, Australia.

Hi I’am Julie Mallet, from France

Hi everyone, my name is Giada, I’m from Italy!

Class 1 - R / Rstudio Installation

R version 4.0 has just been released! This is very exciting (for a number of nerdy reasons) but in this course we will be using R version 3.6.3 (you can use some version of 3.6.x) to keep things consistent with the materials.

Installing R and Rstudio

There is a great guide on how to download and install R if you haven’t already, than can be found here. If you get lost try following this one instead.

Rstudio is not much use to you without R installed, and using R without Rstudio is a lot more effort than it is worth. Ensure that you have both installed, and that Rstudio boots up.

Try setting up your screen like this, in order to follow along.

Downloading the R-markdown document for the first session here.

Class 2 - Variables, types and functions.

Download second file here.

Let’s talk about variables and functions.

Class 3 - Intro to Vectors

Class 3 Files.

Posting of code:

Class 4 - Logical Operations

Link to files

Class 5 - Dataframes!

Linke to files

Link to iris files

Class 6 - Plotting your data with ggplot2.

If you haven’t download the files here:

Let’s start posting out plots.

Class 7

If you have not downloaded files, download here:

Here

Class 8: Programming with R | Part 1

Prograaming with R.

Files here

Class 9: Programming with R | Part 2

Files available here.

If you didn’t save have success with making a function to make the plants grow, use the example one below:

grow_plants <- function(df, dog, growth_amount, sd){

  growth_heights = rnorm(n = 3, mean = growth_amount * dog, sd = sd)

  new_df_values <- data.frame(
    day = rep(dog, 3),
    height = growth_heights,
    plant.id = LETTERS[1:3]
  )

  output_df <- rbind(df, new_df_values)

  return(output_df)
}