27
Building interactive and reproducible reports in minutes Introduction to R Markdown Yan-holtz.com/teaching

Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Buildinginteractiveandreproduciblereportsinminutes

IntroductiontoRMarkdown

Yan-holtz.com/teaching

Page 2: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

What

“AnRMarkdown(.Rmd)fileisarecordofyourresearch.Itcontainsthecode thatascientistneedstoreproduceyourworkalongwiththenarration thatareader

needstounderstandyourwork.“

Why

• Efficiency• Reproducibility• Interactivity• Automation• Notebook

Andmuchmore..

Page 3: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

MostBasicDocument

Page 4: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

1- OpenRstudio:

• UserFriendlyenvironment• Autocompletion• RunalineofcodewithCmd +Enter

Page 5: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

2- Opena.Rmd file:

Page 6: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Anatomyofa.Rmd file:

Header

Title

Text

Codechunk

Page 7: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

3- Knitthe.Rmd file:

Page 8: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

.html.rmd4- .HTML

outputisready

• Havealooktoyourcurrentdirectory

• Openthe.htmlinabrowser

header

TitleText

Code

Coderesult

Page 9: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Customize text

Page 10: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Customizethetext

RMarkdowncheatsheet

bit.ly/1SuNTo9

Page 11: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Codechunk options

Page 12: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

AnatomyofaCodechunk:

Optional:chunk nameR,bash,

python?

Chunkoptions

Run allpreviouschunks

Run thischunk

Commentyour code

Page 13: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Codechunkoptions:

Page 14: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Donotalwaysrunthewholedocument

à RMarkdowndocumentis aNotebook!!

Page 15: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Header

Page 16: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Anatomyoftheheader:

Page 17: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Going further

Page 18: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Insertatable:theDTlibrary

Dataframe

Page 19: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

UseInteractivecharts

Plotly library

Basicggplot2graphic

Ggplotly turn theplotinteractive

Result:zoom/hover /export..Andmore

http://www.htmlwidgets.org

Page 20: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Useatemplate• ThePCTGtemplate:www.github.com/holtzy/epuRate

Page 21: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Pimpmy.Rmd

• holtzy.github.io/Pimp-my-rmd/

• Everything is possible

• UseCSSandHTMLcode

• Add headerandfooter

• More

Page 22: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Sharing

Page 23: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Outputformat?

Word.doc.pdf

Book

TemplateDashboard

Slides

Blog

Page 24: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Shareyouranalysis

• Mailwithcolleagues,supervisor

• Publicationasasupplementarymaterial

• Github:www.github.com

• Website

Page 25: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Example

Page 26: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Anexample:mybioinfo pipeline:

• Interactionwith clusters

• Oneuniquefolder

• Several .rmd wrapped inawebsite

• Shared online

Page 27: Introduction to R Markdown - Yan Holtz · “ An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with

Thanks

bit.ly/2SxJFlVSlides:

bit.ly/2AZySd9Cheat Sheet:

bit.ly/2QDX7HzPimp my rmd:

[email protected]

www.yan-holtz.com

@R_Graph_Gallery

github.com/holtzy