-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic.Rmd
77 lines (64 loc) · 2.05 KB
/
dynamic.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
title: 'Iris: Sepal-Ratio Modeling'
author: "Bastiaan Quast"
date: "Thursday, July 18, 2014"
output:
ioslides_presentation:
keep_md: yes
transition: faster
runtime: shiny
---
# We want to model sepal ratios, do we need separate models for each species?
## Iris dataset
- Included in R package **datasets**
- Originally by Fisher or Anderson
- Measurements for **petal** and **sepal** width and length
- Fifty flowers of three species
- Setosa
- Versicolor
- Virginica
```{r}
str(iris)
```
## LOESS Model
- **Lo**cally W**e**ighted **S**catterplot **S**moothing
- [more info on LOESS](http://en.wikipedia.org/wiki/Local_regression)
- General model and species-specific models
- Standard Error bands
- Grey band for general model
- Coloured bands for respective species
- Adjustable 'wobblyness' of models
- Adjustable point size and opacity
## Results
```{r echo=FALSE, message=FALSE}
# load the ggvis package
library(ggvis)
# load the dplyr package
# for use of magrittr pipe: %>%
library(dplyr)
# lazyload the dataset and pass it to
iris %>%
# the ggvis function, now set the axis
ggvis(~Sepal.Width, ~Sepal.Length) %>%
# add the smoother for all points
layer_smooths(span = input_slider(0.5, 1, 0.5,
label = 'General Model'),
se = TRUE) %>%
# now group by species
group_by(Species) %>%
# add points per species and colour them
layer_points(size := input_slider(10, 200, 50,
label = 'Point Size'),
opacity := input_slider(0.5, 1, 0.5,
label = 'Point Opacity'),
fill = ~Species) %>%
# now add smoothers per species and colour them
layer_smooths(span = input_slider(0.5, 1, 0.5,
label = 'Species Models'),
fill = ~Species, se=TRUE) %>%
# add new labels
add_axis("x", title = "Sepal Width") %>%
add_axis("y", title = "Sepal Length") %>%
# finally declare as shiny object
bind_shiny("ggvis", "ggvis_ui")
```