class: center, middle, inverse, title-slide # Overview: R ## Workshop on Plotting in R ###
Lokesh Mano
• 18-Jan-2022 ### NBIS, SciLifeLab --- exclude: true count: false <link href="https://fonts.googleapis.com/css?family=Roboto|Source+Sans+Pro:300,400,600|Ubuntu+Mono&subset=latin-ext" rel="stylesheet"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous"> <!-- ------------ Only edit title, subtitle & author above this ------------ --> --- name: content class: spaced ## Contents * [Demo: I/O](#demo) * [Special operator](#dplyr) * [Some important functions](#tidyr) --- name: demo ## Reading files * Errors while reading in files! * Demo of things that could go wrong when reading in files into R * Demo on using reserved variables like `T`, `F`, `character` and many others ... * How can you check if something is a reserved variable? --- --- name: dplyr ## Special operator - `%>%` * from the `dplyr` package * works like a pipe -- ```r read.table("data/counts_raw.txt", header = T, row.names = 1, sep = "\t") %>% head(6) ``` ``` ## Sample_1 Sample_2 Sample_3 Sample_4 Sample_5 Sample_6 Sample_7 ## ENSG00000000003 321 303 204 492 455 359 376 ## ENSG00000000005 0 0 0 0 0 0 0 ## ENSG00000000419 696 660 472 951 963 689 706 ## ENSG00000000457 59 54 44 109 73 66 60 ## ENSG00000000460 399 405 236 445 454 374 316 ## ENSG00000000938 0 0 0 0 0 1 0 ## Sample_8 Sample_9 Sample_10 Sample_11 Sample_12 ## ENSG00000000003 523 450 950 760 1436 ## ENSG00000000005 0 0 0 0 0 ## ENSG00000000419 1041 796 1036 789 1413 ## ENSG00000000457 125 74 108 115 174 ## ENSG00000000460 505 398 141 168 259 ## ENSG00000000938 0 0 1 0 0 ``` --- name: dplyr-2 ## Special operator - `%>%` * from the `dplyr` package * works like a pipe ```r read.table("data/counts_raw.txt", header = T, row.names = 1, sep = "\t") %>% head(6) %>% rownames_to_column(var = "Gene") ``` ``` ## Gene Sample_1 Sample_2 Sample_3 Sample_4 Sample_5 Sample_6 ## 1 ENSG00000000003 321 303 204 492 455 359 ## 2 ENSG00000000005 0 0 0 0 0 0 ## 3 ENSG00000000419 696 660 472 951 963 689 ## 4 ENSG00000000457 59 54 44 109 73 66 ## 5 ENSG00000000460 399 405 236 445 454 374 ## 6 ENSG00000000938 0 0 0 0 0 1 ## Sample_7 Sample_8 Sample_9 Sample_10 Sample_11 Sample_12 ## 1 376 523 450 950 760 1436 ## 2 0 0 0 0 0 0 ## 3 706 1041 796 1036 789 1413 ## 4 60 125 74 108 115 174 ## 5 316 505 398 141 168 259 ## 6 0 0 0 1 0 0 ``` --- name: dplyr-3 ## Special operator - `%>%` * from the `dplyr` package * works like a pipe ```r read.table("data/counts_raw.txt", header = T, row.names = 1, sep = "\t") %>% head(1) %>% rownames_to_column(var = "Gene") %>% gather(Sample_ID, count, -Gene) ``` ``` ## Gene Sample_ID count ## 1 ENSG00000000003 Sample_1 321 ## 2 ENSG00000000003 Sample_2 303 ## 3 ENSG00000000003 Sample_3 204 ## 4 ENSG00000000003 Sample_4 492 ## 5 ENSG00000000003 Sample_5 455 ## 6 ENSG00000000003 Sample_6 359 ## 7 ENSG00000000003 Sample_7 376 ## 8 ENSG00000000003 Sample_8 523 ## 9 ENSG00000000003 Sample_9 450 ## 10 ENSG00000000003 Sample_10 950 ## 11 ENSG00000000003 Sample_11 760 ## 12 ENSG00000000003 Sample_12 1436 ``` --- name: tidyr ## Tidyr or dplyr functions * `gather()` - converts wide to long format - `key` is usally what you measure: `-Gene` -- * `select()` - you can choose which columns you want, --- name: join ## Join To merge two different tables to make a combined dataset where you have all the variables together! * `full_join()` * `left_join()` * and more ... -- .pull-center[ <img src="assets/images/dplyr-joins.png" alt="drawing" width="400" height ="400"/> ] --- name: end_slide class: end-slide, middle count: false # Thank you. Questions? .end-text[ <p>R version 4.1.2 (2021-11-01)<br><p>Platform: x86_64-pc-linux-gnu (64-bit)</p><p>OS: Ubuntu 18.04.6 LTS</p><br> <hr> <span class="small">Built on : <i class='fa fa-calendar' aria-hidden='true'></i> 18-Jan-2022 at <i class='fa fa-clock-o' aria-hidden='true'></i> 09:51:20</span> <b>2022</b> • [SciLifeLab](https://www.scilifelab.se/) • [NBIS](https://nbis.se/) ]