-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamgraph-sixhundred-colour-int-makeZazzleGraphic-ig-van-jan2016-avg-colour-ggjoy.R
88 lines (73 loc) · 2.65 KB
/
streamgraph-sixhundred-colour-int-makeZazzleGraphic-ig-van-jan2016-avg-colour-ggjoy.R
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
library(tidyverse)
library(plotrix)
library(ggjoy)
library(R.utils)
library(anytime)
library(streamgraph)
library(htmltools)
library(exportwidget)
library(htmlwidgets)
library(webshot)
args <- commandArgs(asValue=TRUE)
getnumericColour <-
function(colorname) {
colour_matrix=col2rgb(colorname)
return(as.numeric(colour_matrix[1,1]) * 65536 +
as.numeric(colour_matrix[2,1]) * 256 +
as.numeric(colour_matrix[3,1]))
}
main <- function() {
csv_url <-
"https://raw.githubusercontent.com/rtanglao/2016-r-rtgram/master/JANUARY2016/january2016-ig-van-avgcolour-id-mf-month-day-daynum-unixtime-hour-colourname.csv"
average_colour_ig_van_jan2016 <-
read_csv(csv_url)
groupedby_date_sixhundred_colourint <- average_colour_ig_van_jan2016 %>%
rowwise() %>%
mutate(date = anydate(unixtime)) %>%
group_by(date, colourname) %>%
tally() %>%
rowwise() %>%
mutate(sixhundred_colourint = getnumericColour(colourname))
colour_hex_strings_all <-
sapply(groupedby_date_sixhundred_colourint$sixhundred_colourint,
function(x){
sprintf("#%6.6X", x)})
colour_named_vector <-
setNames(as.character(colour_hex_strings_all),
colour_hex_strings_all)
# add sg_fill_manual
## sg <- groupedby_date_sixhundred_colourint %>%
## streamgraph("sixhundred_colourint", "n", "date", interactive=FALSE) %>%
## sg_fill_manual(values=colour_named_vector)
# from https://github.com/timelyportfolio/exportwidget the following also works
## html_print(
## tagList(
## streamgraph( groupedby_date_sixhundred_colourint,
## "sixhundred_colourint", "n", "date",
## interactive=FALSE) %>%
## sg_fill_manual(values=colour_named_vector)
## ,export_widget()
## )) %>%
## normalizePath(.,winslash="/") %>%
## gsub(x=.,pattern = ":/",replacement="://") %>%
## paste0("file:///",.) %>%
## webshot( file = "stream_screen.png", delay = 10 )
# END of working
# from http://www.buildingwidgets.com/blog/2015/4/9/week-14-exporting-widget
html_print(
streamgraph( groupedby_date_sixhundred_colourint,
"sixhundred_colourint", "n", "date",
interactive=FALSE) %>%
sg_fill_manual(values=colour_named_vector),
viewer = NULL
) %>%
normalizePath(.,winslash="/") %>%
gsub(x=.,pattern = ":/",replacement="://") %>%
paste0("file:///",.) %>%
webshot( file = "headless-streamgraph.png", delay = 10 )
#
#saveWidget(sg, "test.html", selfcontained = TRUE) # <- works!
}
sink("log.txt")
main()
sink()