-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtauchartsrpub.Rmd
258 lines (209 loc) · 9.16 KB
/
tauchartsrpub.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
---
title: "TauCharts htmlwidget"
author: "Bob Rudis (@hrbrmstr)"
output:
html_document:
theme: cosmo
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
An R [htmlwidget](http://htmlwidgets.org/) interface to [TauCharts](http://www.taucharts.com/).
[On GitHub](http://github.com/hrbrmstr/taucharts)
Re-create TauCharts web site examples, starting with the data needed for the charts:
```{r init}
# devtools::install_github("hrbrmstr/taucharts")
library(taucharts)
scatter_dat <- structure(list(team = c("d", "d", "d", "d", "l", "l", "l", "l",
"k", "k", "k", "k"), cycleTime = c(1L, 2L, 3L, 4L, 2L, 3L, 4L,
5L, 2L, 3L, 4L, 5L), effort = c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L,
4L, 5L, 6L, 8L), count = c(1L, 5L, 8L, 3L, 1L, 5L, 8L, 3L, 1L,
5L, 8L, 3L), priority = c("low", "low", "medium", "high", "low",
"low", "medium", "high", "low", "low", "medium", "high")), .Names = c("team",
"cycleTime", "effort", "count", "priority"), class = "data.frame", row.names = c(NA, 12L))
line_dat <- structure(list(type = c("us", "us", "us", "us", "us", "us", "bug",
"bug", "bug", "bug", "bug"), count = c(0L, 10L, 15L, 12L, 16L,
13L, 21L, 19L, 23L, 26L, 23L), date = c("12-2013", "01-2014",
"02-2014", "03-2014", "04-2014", "05-2014", "01-2014", "02-2014",
"03-2014", "04-2014", "05-2014")), .Names = c("type", "count",
"date"), class = "data.frame", row.names = c(NA, 11L))
bar_dat <- structure(list(team = c("d", "d", "d", "d", "l", "l", "l", "l",
"k", "k", "k", "k"), cycleTime = c(1L, 2L, 3L, 4L, 2L, 3L, 4L,
5L, 2L, 3L, 4L, 5L), effort = c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L,
4L, 5L, 6L, 8L), count = c(1L, 5L, 8L, 3L, 1L, 5L, 8L, 3L, 1L,
5L, 8L, 3L), priority = c("low", "low", "medium", "high", "low",
"low", "medium", "high", "low", "low", "medium", "high")), .Names = c("team",
"cycleTime", "effort", "count", "priority"), class = "data.frame", row.names = c(NA, 12L))
car_dat <- structure(list(car = c("Toyota Prius+", "Volvo S60", "BMV X5",
"Infinity FX", "Mercedes Vito", "Peugeot 3008", "Subaru Forester",
"Lexus RX", "Bentley Continental"), co2 = c(96L, 135L, 197L,
238L, 203L, 155L, 186L, 233L, 246L), hp = c(99L, 150L, 306L,
238L, 95L, 120L, 150L, 188L, 507L), euroEco = c("eco", "eco",
"non-eco", "non-eco", "non-eco", "non-eco", "non-eco", "non-eco",
"non-eco"), power = c("low", "normal", "high", "high", "low",
"low", "normal", "normal", "high")), .Names = c("car", "co2",
"hp", "euroEco", "power"), class = "data.frame", row.names = c(NA, 9L))
splom_dat <- structure(list(param1 = c("hp", "hp", "hp", "co2", "co2", "co2",
"mpg", "mpg", "mpg", "hp", "hp", "hp", "co2", "co2", "co2", "mpg",
"mpg", "mpg", "hp", "hp", "hp", "co2", "co2", "co2", "mpg", "mpg",
"mpg", "hp", "hp", "hp", "co2", "co2", "co2", "mpg", "mpg", "mpg",
"hp", "hp", "hp", "co2", "co2", "co2", "mpg", "mpg", "mpg", "hp",
"hp", "hp", "co2", "co2", "co2", "mpg", "mpg", "mpg", "hp", "hp",
"hp", "co2", "co2", "co2", "mpg", "mpg", "mpg", "hp", "hp", "hp",
"co2", "co2", "co2", "mpg", "mpg", "mpg", "hp", "hp", "hp", "co2",
"co2", "co2", "mpg", "mpg", "mpg"), param2 = c("hp", "co2", "mpg",
"hp", "co2", "mpg", "hp", "co2", "mpg", "hp", "co2", "mpg", "hp",
"co2", "mpg", "hp", "co2", "mpg", "hp", "co2", "mpg", "hp", "co2",
"mpg", "hp", "co2", "mpg", "hp", "co2", "mpg", "hp", "co2", "mpg",
"hp", "co2", "mpg", "hp", "co2", "mpg", "hp", "co2", "mpg", "hp",
"co2", "mpg", "hp", "co2", "mpg", "hp", "co2", "mpg", "hp", "co2",
"mpg", "hp", "co2", "mpg", "hp", "co2", "mpg", "hp", "co2", "mpg",
"hp", "co2", "mpg", "hp", "co2", "mpg", "hp", "co2", "mpg", "hp",
"co2", "mpg", "hp", "co2", "mpg", "hp", "co2", "mpg"), value1 = c(99,
99, 99, 96, 96, 96, 3.8, 3.8, 3.8, 150, 150, 150, 135, 135, 135,
7.4, 7.4, 7.4, 306, 306, 306, 197, 197, 197, 11.2, 11.2, 11.2,
238, 238, 238, 238, 238, 238, 11.2, 11.2, 11.2, 95, 95, 95, 203,
203, 203, 9.4, 9.4, 9.4, 120, 120, 120, 155, 155, 155, 9.2, 9.2,
9.2, 150, 150, 150, 186, 186, 186, 10.4, 10.4, 10.4, 188, 188,
188, 233, 233, 233, 13.3, 13.3, 13.3, 507, 507, 507, 246, 246,
246, 15.4, 15.4, 15.4), value2 = c(99, 96, 3.8, 99, 96, 3.8,
99, 96, 3.8, 150, 135, 7.4, 150, 135, 7.4, 150, 135, 7.4, 306,
197, 11.2, 306, 197, 11.2, 306, 197, 11.2, 238, 238, 11.2, 238,
238, 11.2, 238, 238, 11.2, 95, 203, 9.4, 95, 203, 9.4, 95, 203,
9.4, 120, 155, 9.2, 120, 155, 9.2, 120, 155, 9.2, 150, 186, 10.4,
150, 186, 10.4, 150, 186, 10.4, 188, 233, 13.3, 188, 233, 13.3,
188, 233, 13.3, 507, 246, 15.4, 507, 246, 15.4, 507, 246, 15.4
)), .Names = c("param1", "param2", "value1", "value2"), class = "data.frame", row.names = c(NA,
81L))
```
Now, mimic a good chunk of section 5 (and some others) of the [TauCharts basic examples](http://api.taucharts.com/basic/index.html). Interestingly enough, faceted charts work without any real code changes:
```{r charts_1}
tauchart(scatter_dat) %>%
tau_point("cycleTime", "effort", "team", "count")
```
### ordered factors!
```{r charts_ordered}
scatter_dat %>%
{
data.frame(
.,
cycleTimeFactor =factor(.$cycleTime,
levels=rev(unique(.$cycleTime)),
ordered=TRUE)
)
} %>%
tauchart %>%
tau_point("cycleTimeFactor", "effort", "team", "count")
```
### custom colors!
```{r charts_2}
tauchart(scatter_dat) %>%
tau_point("cycleTime", "effort", "team", "count") %>%
tau_color_manual(c("orange", "green", "black"))
tauchart(line_dat) %>%
tau_line("date", "count", "type") %>%
tau_guide_x(label="Month") %>%
tau_guide_y(label="Count of completed entities", label_padding=50) %>%
tau_guide_padding(70, 70, 10, 10)
tauchart(bar_dat) %>% tau_bar("team", "effort")
tauchart(bar_dat) %>% tau_bar("team", "effort", "priority")
tauchart(bar_dat) %>% tau_bar("effort", "team", horizontal=TRUE)
tauchart(bar_dat) %>% tau_bar("effort", "team", "priority", horizontal=TRUE)
```
### legendary!
```{r chart_leg}
tauchart(car_dat) %>%
tau_point("power", "co2", color="euroEco") %>%
tau_legend()
```
### tooltips!
```{r chart_tips}
tauchart(car_dat) %>%
tau_point("power", "co2", color="euroEco") %>%
tau_legend() %>%
tau_tooltip()
```
### basic facets!
```{r charts_3}
print(car_dat)
tauchart(car_dat) %>%
tau_point(c('euroEco', 'co2'), c('power', 'hp'))
```
### scatterplot matrices!
```{r charts_4}
tauchart(splom_dat) %>%
tau_point(c("param1", "value1"), c("param2", "value2"))
```
### trends!
```{r trends}
tc <- tauchart(car_dat) %>%
tau_point( "hp", c("euroEco","co2"), color = "euroEco" ) %>%
tau_legend( ) %>%
tau_tooltip( )
tc %>%
tau_trendline( ) #using defaults
tc %>%
#type does not seem to work as expected
# so use models instead to change default type or order of dropdown
tau_trendline( models = c( "logarithmic", "exponential" ) )
tc %>%
# start with unclicked TREND LINE
tau_trendline( showTrend = FALSE )
tc %>%
#take the fun away from the user
tau_trendline( showPanel = FALSE )
```
## Now do some other things outside the examples
### customize y axis labels!
```{r custom_1}
how_good <- structure(list(
Ranking = structure(
1:5, .Label = c("Bottom", "Bellow Average",
"Average", "Above Average", "Top"), class = "factor"
), Prob = c(30L, 10L, 15L, 40L, 5L)/100
), .Names = c("Ranking", "Prob"), row.names = c(NA,-5L), class = "data.frame")
# NOTE my division by 100 in Prob above
tauchart(how_good) %>%
tau_bar(x="Ranking", y="Prob") %>%
tau_guide_y(tick_format="%")
```
### the whole shebang!
```{r shebang}
data(cars_data)
tauchart(cars_data) %>%
tau_point("milespergallon", c("class", "price"), color="class") %>%
tau_legend() %>%
tau_trendline() %>%
tau_tooltip(c("vehicle", "year", "class", "price", "milespergallon"))
```
### custom CSS rules!
```{r custom_styles}
make_black_tooltip <- function(tau) {
tau %>%
tau_add_css_rule(".tau-chart__tooltip { background: black; color: white; }") %>%
tau_add_css_rule(".tau-chart__tooltip__exclude:hover { color: #65717f; background: linear-gradient(to right, rgba(255, 255, 255, 0) 100%, rgba(235, 238, 241, 0.9) 0%); }") %>%
tau_add_css_rule(".tau-chart__tooltip__exclude { color: white; }") %>%
tau_add_css_rule(".tau-chart__tooltip__list__elem { color: white; }") %>%
tau_add_css_rule(".tau-chart__tooltip__list__elem:first-child { color: white; font-weight: bold; }") %>%
tau_add_css_rule(".tau-chart__tooltip__gray-text { color: white; font-weight: bold; }")
}
tauchart(mtcars) %>%
tau_point("wt", "mpg", color="cyl") %>%
tau_color_manual(c("blue", "maroon", "black")) %>%
tau_tooltip() %>%
make_black_tooltip()
```
alternatively
```{r multi_styles}
tauchart(mtcars) %>%
tau_point("wt", "mpg", color="cyl") %>%
tau_color_manual(c("blue", "maroon", "black")) %>%
tau_tooltip() %>%
tau_add_css_rule(c(".tau-chart__tooltip { background: black; color: white; }",
".tau-chart__tooltip__exclude:hover { color: #65717f; background: linear-gradient(to right, rgba(255, 255, 255, 0) 100%, rgba(235, 238, 241, 0.9) 0%); }",
".tau-chart__tooltip__exclude { color: white; }",
".tau-chart__tooltip__list__elem { color: white; }",
".tau-chart__tooltip__list__elem:first-child { color: white; font-weight: bold; }",
".tau-chart__tooltip__gray-text { color: white; font-weight: bold; }"))
```
FIN