-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVersion4.Rmd
159 lines (132 loc) · 3.15 KB
/
Version4.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
---
title: "Version 4: Customize"
author: "Jenna Landy"
output:
rmdformats::robobook
params:
package_location:
label: "Path to Iris Project Package:"
value: "./irisproject/"
input: text
convert_cm:
label: "Convert Centimeters to Inches?"
value: TRUE
plot_pairs_of:
label: "Variables to Include in Pairs Plot (comma separated):"
value: "Sepal.Length, Sepal.Width, Petal.Length, Petal.Width, Length.Ratio, Width.Ratio, Circumference, Species"
input: text
---
```{css, echo = FALSE}
.book {
padding-top: 40px
}
.book .book-body .page-inner section.normal h1, .book .book-body .page-inner section.normal h2, .book .book-body .page-inner section.normal h3, .book .book-body .page-inner section.normal h4 {
padding-top: 40px
}
```
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
rm(list = c('iris'))
```
# Setup {.tabset .tabset-fade .tabset-pills}
## Packages
```{r}
# use install.packages FIRST TIME ONLY
update.packages(
params$package_location,
repos=NULL,
type="source"
)
library(irisproject)
library(dplyr)
library(ggplot2)
library(plotly)
```
## Parameters
```{r}
for (p in names(params)) {
print(paste0(p, ': ', params[[p]]))
}
```
# Starting Data
```{r}
head(iris) %>%
knitr::kable(digits = 3)
```
# Data Manipulation {.tabset .tabset-fade .tabset-pills}
`r if(params$convert_cm) {"## Convert Measurements"}`
`r if(params$convert_cm) {"Converting data in first four columns from centimeters to inches"}`
```{r include = params$convert_cm}
if (params$convert_cm) {
iris <- iris %>%
convert_measurements(1:4)
}
```
## Ratio features
Computing two ratio features: ratio of lengths (sepal : petal) and ratio of widths (sepal : petal)
```{r}
iris <- iris %>%
compute_ratios()
```
## Circumference
Creating a new feature: circumference of the smallest circle that could circumscribe the flower (using the larger length as the radius).
```{r}
iris <- iris %>%
compute_circumference()
```
# Final Data
```{r}
head(iris) %>%
knitr::kable(digits = 3)
```
# Plots
## Pairs plot of select variables
```{r}
plot_pairs_of <- strsplit(params$plot_pairs_of, ",")[[1]] %>% trimws()
```
```{r results="asis", echo= FALSE}
cat(knitr::asis_output("Variables included:\n\n"))
for (var in plot_pairs_of) {
cat(knitr::asis_output(paste0(
"- ",
var,
"\n"
)))
}
```
```{r}
pairs(iris[,plot_pairs_of])
```
## Plot of circumference and length ratio by species
```{r}
p <- iris %>% ggplot(aes(
x = Circumference,
y = Length.Ratio,
color = Species,
text = paste0(
"Species: ", Species,
"\nCircumference: ", round(Circumference,3),
"\nLength Ratio: ", round(Length.Ratio, 3),
"\nWidth Ratio: ", round(Width.Ratio, 3),
"\nPetal Width, Length: ", round(Petal.Width, 3),
", ", round(Petal.Length, 3),
"\nSepal Width, Length: ", round(Sepal.Width, 3),
", ", round(Sepal.Length, 3)
)
)) +
geom_point() +
theme_classic() +
theme(
legend.position = 'top',
legend.justification = 'left'
)
plotly::ggplotly(p, tooltip = c("text")) %>%
plotly::layout(
legend = list(
orientation = "h",
x = 0,
yanchor = "bottom",
y = 1.02
)
)
```