This presentation was made in RStudio using RMarkdown!
- Can set
output: ioslides_presentationin the header
2/9/2018
This presentation was made in RStudio using RMarkdown!
output: ioslides_presentation in the headerR commands are like sentences:
draw(picture, recipient = "me", material = "paint")
| Component | Role |
|---|---|
| draw | function |
| picture | argument value |
| recipient | argument name |
| "me" | argument value |
| material | argument name |
| "paint" | argument value |
%>%)takes the thing on the left, and (by default) puts it (or its output, if it is a function call) into the first argument slot for the function on the right
We'll do a lot more with this later
## Two equivalent expressions arbuthnot %>% mutate(total = boys + girls) mutate(arbuthnot, total = boys + girls)
mutate() function## Creates the column, but it immediately disappears mutate(arbuthnot, total = boys + girls) ## Creates the column, and creates a brand new data frame ## that has both new and old variables (now we have two ## data frames, one with and one without the new variable) new.arbuthnot <- mutate(arbuthnot, total = boys + girls) ## Creates the column, and overwrites the original data ## with a data frame that has new and old columns arbuthnot <- mutate(arbuthnot, total = boys + girls)
Source: Nathan Yau, Data Points
Source: Nathan Yau, Data Points
Source: Nathan Yau, Data Points
Source: Nathan Yau, Data Points
Source: Nathan Yau, Data Points
Source: New York Times
Cleveland and McGill (1985): people better at judging:
ggplot2 (Hadley Wickham, 2010)
ggplot (or ggplot1) was sort of a beta version; not really used todayggplot2| Graphical element | ggplot2 object(s) |
|---|---|
| The data | data= argument |
| Geometric objects | geom_*() functions |
| Mappings of variables to cues | aes() function |
| Scales | scale_*() functions |
| Faceting | facet_wrap(), facet_grid() |
The basic operation is combination of these elements via the + operator. A fully formed combination returns a plot as an R object (can be assigned to things, operated on later, etc.)
Plots must at a minimum have data (data=), a mapping (aes()), and at least one geometry element (geom_*())
library(tidyverse) ggplot(data = mtcars, aes(x = disp, y = mpg)) + geom_point()
ggplot(data = mtcars, aes(x = disp, y = mpg, color = factor(cyl))) + geom_point() + geom_line() + facet_wrap(~am) + scale_color_brewer(palette = "Set1")