Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
r_hadleyverse [2016/11/02 21:25]
xaviergb [ggplot2 - Challenge # 2]
r_hadleyverse [2016/11/02 22:46] (current)
xaviergb [Workshop 3: Intro to ggplot2, tidyr & dplyr]
Line 15: Line 15:
 Link to associated Prezi: [[http://​prezi.com/​daz9r0cj1si4/​|Prezi]] Link to associated Prezi: [[http://​prezi.com/​daz9r0cj1si4/​|Prezi]]
  
-Download the R script for this lesson: ​[[http://​qcbs.ca/​wiki/​_media/​ggplot.r|Script]]+Download the R script for this lesson: ​{{:workshop3.r|Script}}
 ===== 1. Plotting in R using the Grammar of Graphics (ggplot2) ===== ===== 1. Plotting in R using the Grammar of Graphics (ggplot2) =====
  
Line 97: Line 97:
 ===== ggplot2 - Challenge #1 ===== ===== ggplot2 - Challenge #1 =====
  
-Using the ''​qplot()''​ function, build a basic scatter plot with a title and axis labels from one of the ''​CO2''​ or ''​BOD''​ data sets in R. You can load these and explore their contents as follows:+//Using the ''​qplot()''​ function, build a basic scatter plot with a title and axis labels from one of the ''​CO2''​ or ''​BOD''​ data sets in R. You can load these and explore their contents as follows://
  
 <code rsplus | > <code rsplus | >
Line 731: Line 731:
  
 **Change data from wide to long format** **Change data from wide to long format**
-//(See back to Section ​6.3)// +//(See back to Section ​2.3)// 
  
 <code rsplus | > <code rsplus | >
Line 960: Line 960:
  
 ---- ----
-**CHALLENGE:**+ 
 +===== dplyr CHALLENGE ​=====
 //Using the ''​ChickWeight''​ dataset, create a summary table which displays the weight gain of individual chicks in the study. Employ ''​dplyr''​ verbs and the ''​%>​%''​ operator.// //Using the ''​ChickWeight''​ dataset, create a summary table which displays the weight gain of individual chicks in the study. Employ ''​dplyr''​ verbs and the ''​%>​%''​ operator.//
  
Line 988: Line 989:
 ---- ----
  
-Note that we can group the data frame using more than one factor, using the general syntax as follows: ''​group_by(group1,​ group2, ...)''​. This approach allows us to carry out operations on ''​group2''​ while conserving information on ''​group1''​ within the summary table. ​** HINT HINT **+==== Ninja Hint ==== 
 + 
 +Note that we can group the data frame using more than one factor, using the general syntax as follows: ''​group_by(group1,​ group2, ...)''​. This approach allows us to carry out operations on ''​group2''​ while conserving information on ''​group1''​ within the summary table. ​
  
 ---- ----
-**dplyr NINJA CHALLENGE:**+ 
 +===== dplyr NINJA CHALLENGE ​=====
 //Using the ''​ChickWeight''​ dataset, create a summary table which displays the average weight gain of individual chicks for each diet in the study. Employ ''​dplyr''​ verbs and the ''​%>​%''​ operator.// //Using the ''​ChickWeight''​ dataset, create a summary table which displays the average weight gain of individual chicks for each diet in the study. Employ ''​dplyr''​ verbs and the ''​%>​%''​ operator.//
  
Line 1029: Line 1033:
 ===== 4. Resources ===== ===== 4. Resources =====
  
-Here are some great resources for learning tidyr and dplyr that we used when compiling this workshop:+Here are some great resources for learning ​ggplot2, ​tidyr and dplyr that we used when compiling this workshop:
  
-//Reshape / Reshape2// +//ggplot2// 
-  * [[http://seananderson.ca/2013/10/​19/​reshape.html]] +  * [[http://shinyapps.stat.ubc.ca/r-graph-catalog/|The R Graph Catalog]] 
-  * [[http://had.co.nz/reshape/​introduction.pdf]] +  * [[https://www.rstudio.com/wp-content/uploads/2015/03/ggplot2-cheatsheet.pdf|The RStudio ggplot2 Cheat Sheet]]
-  * [[http://​cran.r-project.org/web/packages/reshape2/reshape2.pdf]]+
  
 Lecture notes from Hadley'​s course Stat 405 (the other lessons are awesome too!) Lecture notes from Hadley'​s course Stat 405 (the other lessons are awesome too!)
Line 1040: Line 1043:
   * [[http://​stat405.had.co.nz/​lectures/​19-tables.pdf]]   * [[http://​stat405.had.co.nz/​lectures/​19-tables.pdf]]
  
-//dplyr// +//​dplyr ​and tidyr// 
-  * [[https://​cran.rstudio.com/​web/​packages/​dplyr/​vignettes/​introduction.html]] +  * [[https://​www.rstudio.com/​wp-content/​uploads/​2015/​02/​data-wrangling-cheatsheet.pdf|The RStudio Data Wrangling Cheat Sheet]] 
-  * [[http://​seananderson.ca/​2014/​09/​13/​dplyr-intro.html]]+  * [[https://​cran.rstudio.com/​web/​packages/​dplyr/​vignettes/​introduction.html|CRAN Intro to dplyr]] 
 +  * [[http://​seananderson.ca/​2014/​09/​13/​dplyr-intro.html|Sean Anderson'​s Intro to dplyr and pipes]] 
 +  * [[https://​rpubs.com/​bradleyboehmke/​data_wrangling|Bradley Boehmke'​s Intro to data wrangling]]