Datenanalyse mit R

10 - R Markdown zur Kommunikation

Saskia A. Otto
BSH 11/02 - 13/02 2019

R Markdown

How to go from R to any output format for sharing your results?

By using R Markdown

  • R Markdown is an easy-to-write plain text formatter designed to make web content, reports or presentations easy to create,
  • can weave the outputs of your R code, like figures and tables, with text to create a report,
  • supports not only the reproducibility of your analysis but also the entire report,
  • supports various different static as well as dynamic output formats.
  • How does it work? R Markdown encapsulates various processs into a single render function:

modified from the R Markdown cheat sheet (under CC-BY-SA license)

A quick introduction

How to create an .Rmd file

Structure of an .Rmd file

Structure of an .Rmd file

Rendering Output

(Markdown) Syntax

HTML vs Markdown vs R Markdown Syntax

Get more infos

Your turn...

Task: Convert an R script into a Markdown file

Start your first R Markdown file that should render a html document and save it under any name. In lecture 8 on visualizations you were asked to answer the following questions using the hydro dataset (file "data/1111473b.csv"):

  1. What happens if you make a scatterplot of station (x) vs temp (y)? Why is the plot not useful? What would be a better plot?
  2. What happens if you make a boxplot of cruise (x) vs psal (y)? Why is this plot less suitable? What could be an alternative?

If you have done this exercise you can simply use your code and copy and paste it into the code chunks of your .Rmd file. If you haven't done the exercise you have now the opportunity to make up leeway.

Implement the following in your .Rmd file

  1. Start with R code chunks for loading the data and required libraries
  2. Add code chunks for i) any data modifications ii) any plot
  3. Think about which code chunks should be evaluated (eval=TRUE) or not displayed (echo=FALSE)
  4. Think about the dimensions of the figure and add the required specifications in the chunk options
  5. Include different headers and subheaders
  6. Add your answers and think about whether you want to use i) any ordered or unordered lists ii) text in bold or italic
  7. Add a webside link that fits to the topic
  8. Add an image

Note:

Try to knit your .Rmd file frequently (after any major addition)!! It is highly likely that you will run into an error message and that way you can identify the cause much faster.

How do you feel now.....?

Totally confused?

Totally bored?

plot of chunk unnamed-chunk-7

Use the code from the demo file and convert that into your own R Markdown file

Totally content?

Bei weiteren Fragen kontaktieren Sie mich unter:
saskia.otto@uni-hamburg.de

http://www.researchgate.net/profile/Saskia_Otto
http://www.github.com/saskiaotto

Creative Commons License
Diese Arbeit ist lizensiert unter der Creative Commons Attribution-ShareAlike 4.0 International License
mit Ausnahme externer Materialien gekennzeichnet durch die source: Angabe.
Bild auf Titel- und Abschlussfolie: Frühjahrsblüte in der Nordsee
USGS/NASA Landsat: Spring Color in the North Sea, Landsat 8 - OLI, May 7, 2018
(unter CC0 lizenz)