Introduction to R and Rstudio


  • Use RStudio for writing and executing R code
  • Add comments to your code by starting a line with #
  • Assign values to variables using the assignment operator <-
  • Functions covert inputs to outputs
  • Vectors are a collection of values of the same type
  • Following best practices will help the with the correctness and readability of your R code

Reading in data


  • Use readxl::read_xlsx() to import data from excel
  • Use readr::read_tsv(), readr::read_csv(), readr::read_delim() to import data from delimited text files

Tidy data


  • Tidy data is often easier to work with
  • Pivot long to wide with pivot_wider()
  • Pivot wide to long with pivot_longer()

Data wrangling


  • Use summarise() to summarise your data
  • Use mutate() to add new columns
  • Use filter() to filter rows by a condition
  • Use select() to remove or only retain certain rows
  • Use arrange() to re-order rows
  • Use group_by() to group data by the values in particular columns
  • Use joins to combine two data frames

Data visualization


  • Use ggplot() to create a plot and specify the default dataset and aesthetic (aes())
  • Use geoms to specify how the data should be displayed
  • Use facet_wrap() and facet_grid() to create facets
  • Use scales to change the scales in your plot
  • Use theme() and theme presets to modify plot appearance
  • Use patchwork or cowplot to combine plots into one figure

Bioconductor and other bioinformatics packages


  • Use BiocManager to install Bioconductor packages
  • Use Biostrings for working with biological sequences
  • Use karyoploteR or circlize for plotting genomic features
  • Use EdgeR and DEseq2 for differential expression analysis
  • Use Seurat and Monocle3 for single-cell RNA-seq data analysis

Using R markdown for notebooks and documents


  • Specify document-wide properties in the header
  • Use markdown element to format text
  • Use code chunks to run R code
  • Render your notebook using the buttons in Rstudio, or using rmarkdown::render()

Version control with git


  • Keep your files safe and keep track of changes with version control
  • Use github as a remote repository for your code
  • Stage and commit changes to your files so that git keeps track of them
  • Push your changes to your remote repository, and pull changes made by others

Case study


  • You can refer back to this lesson if you want to analyse peptide dat in R