Source file ⇒ R1.Rmd

Today

  1. Install DataComputing on your computer
  2. Introduction to RMarkdown (see Reporting with R Markdown in DataCamp) –do first three chapters
  3. Basics of R (see Introduciton to R in Data Computing) – do entire course
  4. Introduction to ggplot (see DataCamp DataVisualization with ggplot2 course) –do first four chapters

1. First things first:

Install DataComputing on your computer:

install.packages("devtools")
devtools::install_github("DataComputing/DataComputing")

2. R Markdown

Here is a good reference

How to make an html document.

3. Basics of R.

Most important data structures are vectors and data tables.

4. Introduction to ggplot

Graphics and their Grammar

ggplot2 is a grpahics package that uses the components of graphs (i.e. glyphs, aestetics, frames, scales, layers) –called the grammar of graphics.

examples

Here is the data table mosaicData::CPS85:

frame <- CPS85 %>% ggplot(aes(x=age,y=wage)) 
frame + geom_point()

frame <- CPS85 %>% ggplot(aes(x=age,y=wage)) 
frame + geom_point(aes(shape=sex))

frame <- CPS85 %>% ggplot(aes(x=age,y=wage)) 
frame + geom_point(aes(shape=sex)) + facet_grid(married ~ .)

frame <- CPS85 %>% ggplot(aes(x=age,y=wage)) 
frame + geom_point(aes(shape=married)) + ylim(0,30)

BabyNames %>%
  group_by(name) %>%
  summarise(tot=sum(count)) %>%
  arrange(desc(tot)) %>%
  head(3)
name tot
James 5114325
John 5095590
Robert 4809858

Here is a cheet sheet: (Rstudio)[https://www.rstudio.com/wp-content/uploads/2015/03/ggplot2-cheatsheet.pdf]

It is important to be able to look up the syntax and aesetics for the different geoms. Here is a good resourse from ggplot2.org

Your turn

Please make

CPS85 %>% ggplot(aes(x=age,wage)) + geom_point(aes(color=married)) + facet_wrap(~sex)