-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathstreamgraph.Rmd
89 lines (73 loc) · 2.25 KB
/
streamgraph.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
---
title: "streamgraph"
output:
html_document:
keep_md: true
md_document:
variant: markdown_github
---
[GitHub repo](http://github.com/hrbrmstr/streamgraph)
```{r movies, fig.width=10, message=FALSE}
library(streamgraph)
library(dplyr)
library(babynames)
library(DT)
ggplot2movies::movies %>%
select(year, Action, Animation, Comedy, Drama, Documentary, Romance, Short) %>%
tidyr::gather(genre, value, -year) %>%
group_by(year, genre) %>%
tally(wt=value) -> dat
streamgraph(dat, "genre", "n", "year", interactive=TRUE) %>%
sg_axis_x(20, "year", "%Y") %>%
sg_fill_brewer("PuOr")
```
```{r WillTurman, fig.width=10}
data <- read.csv("http://bl.ocks.org/WillTurman/raw/4631136/data.csv", stringsAsFactors=FALSE)
data$date <- as.Date(data$date, format="%m/%d/%y")
streamgraph(data, interactive=TRUE) %>% sg_colors("Reds")
```
```{r fig.width=10}
dat <- read.csv("http://asbcllc.com/blog/2015/february/cre_stream_graph_test/data/cre_transaction-data.csv")
dat %>%
streamgraph("asset_class", "volume_billions", "year", interpolate="cardinal") %>%
sg_axis_x(1, "year", "%Y") %>%
sg_fill_brewer("PuOr")
```
```{r echo=FALSE}
datatable(dat)
```
```{r fig.width=10}
dat %>%
streamgraph("asset_class", "volume_billions", "year", offset="silhouette", interpolate="step") %>%
sg_axis_x(1, "year", "%Y") %>%
sg_fill_brewer("PuOr")
```
```{r fig.width=10}
dat %>%
streamgraph("asset_class", "volume_billions", "year", offset="zero", interpolate="cardinal") %>%
sg_axis_x(1, "year", "%Y") %>%
sg_fill_brewer("PuOr") %>%
sg_legend(TRUE, "Asset class: ")
```
Now, who let that stacked bar chart get in here `;-)`
```{r fig.width=10}
dat %>%
streamgraph("asset_class", "volume_billions", "year", offset="zero", interpolate="step") %>%
sg_axis_x(1, "year", "%Y") %>%
sg_fill_brewer("PuOr")
```
```{r fig.width=10}
# get top 10 names for each year by sex
babynames %>%
group_by(year, sex) %>%
top_n(10, n) -> dat1
# just look at female names and get the data for
# the top n by all years to see how they "flow"
babynames %>%
filter(sex=="F",
name %in% dat1$name) -> dat
streamgraph(dat, "name", "n", "year") %>%
sg_fill_tableau() %>%
sg_axis_x(tick_units = "year", tick_interval = 10, tick_format = "%Y") %>%
sg_legend(TRUE, "Name: ")
```