R Markdown from R Studio - Intro

R Markdown provides an authoring framework for data science. You can use a single R Markdown file to both

  • save and execute code *generate high quality reports that can be shared with an audience

R Markdown documents are fully reproducible and support dozens of static and dynamic output formats. This 1-minute video provides a quick tour of what’s possible with R Markdown:

Installation

Like the rest of R, R Markdown is free and open source. You can install the R Markdown package from CRAN with:

install.packages("rmarkdown")

R Markdown Cheatsheet R Markdown Reference Guide

Viridis colors

Code below demonstrates to color palettes in the viridis package. Each plot displays a contour map of the Maunga Whau volcano in Auckland, New Zealand.

Magma colors

colorFunc <- "heat.colors"
# colorFunc <- "terrain.colors"
# colorFunc <- "topo.colors"
# colorFunc <- "cm.colors"
# colorFunc <- "rainbow"
Heat color example

Heat color example

Simple Demo languages

Bash

ls *.Rmd

Python

x = 'hello, python world!'
print(x.split(' '))

marmap

data(list = params$data)
autoplot(get(params$data))

Tables

Below packages are for tables

It is also very easy to make tables with knitr’s kable function:

Note the use of the results=‘asis’ chunk option. This is required to ensure that the raw table output isn’t processed further by knitr.

A knitr kable.
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2

Markdown Basics

You can use Pandoc’s Markdown to make:

A level-one header

Headers

A level-two header

ATX-style level-two header

ATX-style level-three header

Level-one header

My header

My other header

Level-one unnumbered header

Level-one unnumbered header

Dogs?–in my house?

Lists

Bullet Lists

  • one

  • two

  • three

  • one

  • two

  • three

  • here is my first list item.

  • and my second.

  • here is my first list item.

  • and my second.

The four-space rule

  • First paragraph.

    Continued.

  • Second paragraph. With a code block, which must be indented eight spaces:

    { code }

  • fruits

    • apples
      • macintosh
      • red delicious
    • pears
    • peaches
  • vegetables

    • broccoli
    • chard
  • A lazy, lazy, list item.

  • Another one; this looks bad but is legal.

    Second paragraph of second list item.

Ordered Lists

  1. one
  2. two
  3. three

and this one:

  1. one
  2. two
  3. three

fancy_lists

  1. one
  2. two

Extension: startnum

  1. Ninth
  2. Tenth
  3. Eleventh
    1. subone
    2. subtwo
    3. subthree
  1. Two
  2. Three
  1. Four
  • Five

Default Marker

  1. one
  2. two
  3. three

Term 1

: Definition 1

Term 2 with inline markup

Definition 2

{ some code, part of Definition 2 }

Third paragraph of definition 2.