@@ -35,9 +35,9 @@ accumulate_by <- function(dat, var) {
35
35
}
36
36
37
37
d <- txhousing
38
- fig <- fig %>%
38
+ fig <- d %>%
39
39
filter(year > 2005, city %in% c("Abilene", "Bay Area"))
40
- fig <- d %>% accumulate_by(~date)
40
+ fig <- fig %>% accumulate_by(~date)
41
41
42
42
43
43
fig <- fig %>%
@@ -73,6 +73,7 @@ fig <- fig %>% animation_button(
73
73
)
74
74
75
75
fig
76
+
76
77
```
77
78
78
79
### Filled-Area Animation
@@ -96,48 +97,44 @@ accumulate_by <- function(dat, var) {
96
97
dplyr::bind_rows(dats)
97
98
}
98
99
99
- df <- df
100
- fig <- fig %>%
101
- accumulate_by(~ID)
102
-
103
- fig <- df
100
+ fig <- df %>% accumulate_by(~ID)
104
101
fig <- fig %>% plot_ly(
105
- x = ~ID,
106
- y = ~AAPL.Close,
107
- frame = ~frame,
108
- type = 'scatter',
109
- mode = 'lines',
110
- fill = 'tozeroy',
111
- fillcolor='rgba(114, 186, 59, 0.5)',
112
- line = list(color = 'rgb(114, 186, 59)'),
113
- text = ~paste("Day: ", ID, "<br>Close: $", AAPL.Close),
114
- hoverinfo = 'text'
115
- )
102
+ x = ~ID,
103
+ y = ~AAPL.Close,
104
+ frame = ~frame,
105
+ type = 'scatter',
106
+ mode = 'lines',
107
+ fill = 'tozeroy',
108
+ fillcolor='rgba(114, 186, 59, 0.5)',
109
+ line = list(color = 'rgb(114, 186, 59)'),
110
+ text = ~paste("Day: ", ID, "<br>Close: $", AAPL.Close),
111
+ hoverinfo = 'text'
112
+ )
116
113
fig <- fig %>% layout(
117
- title = "AAPL: Last 30 days",
118
- yaxis = list(
119
- title = "Close",
120
- range = c(0,250),
121
- zeroline = F,
122
- tickprefix = "$"
123
- ),
124
- xaxis = list(
125
- title = "Day",
126
- range = c(0,30),
127
- zeroline = F,
128
- showgrid = F
129
- )
130
- )
131
- fig <- fig %>% animation_opts(
132
- frame = 100,
133
- transition = 0,
134
- redraw = FALSE
114
+ title = "AAPL: Last 30 days",
115
+ yaxis = list(
116
+ title = "Close",
117
+ range = c(0,250),
118
+ zeroline = F,
119
+ tickprefix = "$"
120
+ ),
121
+ xaxis = list(
122
+ title = "Day",
123
+ range = c(0,30),
124
+ zeroline = F,
125
+ showgrid = F
135
126
)
127
+ )
128
+ fig <- fig %>% animation_opts(
129
+ frame = 100,
130
+ transition = 0,
131
+ redraw = FALSE
132
+ )
136
133
fig <- fig %>% animation_slider(
137
- currentvalue = list(
138
- prefix = "Day "
139
- )
134
+ currentvalue = list(
135
+ prefix = "Day "
140
136
)
137
+ )
141
138
142
139
fig
143
140
```
0 commit comments