-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpresentation_plotly.rmd
81 lines (58 loc) · 1.81 KB
/
presentation_plotly.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
---
title: "Week 3 Assignment"
author: "Hailu Teju"
date: "November 18, 2017"
output: ioslides_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Iris Data
```{r, comment="", echo=TRUE}
str(iris)
```
## Interactive Plot - using plotly
In the next few slides we generate scatter plots of Petal.Length vs Sepal.Length using plotly and the following plot options:
- set color equal to the factor variable Species
- set color equal to the continuous variable Sepal.Width
- scaling the size of the points in terms of Petal.Width
## Colored using Species
```{r, message=FALSE}
library(plotly)
(plot_ly(data=iris, x=~Sepal.Length, y=~Petal.Length, type="scatter", color=~Species))
```
## Colored using Sepal.Width
```{r, message=FALSE}
library(plotly)
(plot_ly(data=iris, x=~Sepal.Length, y=~Petal.Length, type="scatter", color=~Sepal.Width))
```
## Scaled using Petal.Width
```{r, message=FALSE}
library(plotly)
(plot_ly(data=iris, x=~Sepal.Length, y=~Petal.Length, type="scatter", size=~Petal.Width))
```
## Box-plot
```{r}
(plot_ly(iris, x = ~Species, y=~Sepal.Length, color = ~Species, type = "box"))
```
## 3D Stuff
```{r, message=FALSE}
ucount <- 300
vcount <- 100
x <- c()
y <- c()
z <- c()
c <- c()
for (i in 1:ucount) {
for (j in 1:vcount ){
x <- c(x, 2*(1-exp(i/(300)))*cos(i/300 * 15.9)*cos(j/32)*cos(j/32))
y <- c(y, 2*(-1 + exp(i/(300)))*sin(i/300 * 15.9)*cos(j/32)*cos(j/32))
z <- c(z, 1-exp(2*i/300)-sin(j/16)+exp(i/300)*sin(j/16))
c <- c(c, i)
}
}
data <- data.frame(x, y, z, c)
(plot_ly(data, x = ~x, y = ~y, z = ~z, type = 'scatter3d', mode = 'lines',
line = list(width = 5, color = ~c, colorscale = "Viridis")))
```
## The End!