11library(htmltools )
22library(reactR )
3+ library(tidyr )
34
45# cat(
56# babel_transform(
@@ -8,43 +9,39 @@ library(reactR)
89# file = "../semiotic/dotplot.js"
910# )
1011
12+ # for now use temporarily build standalone from my github
13+ # but hope this gets resolved with
14+ # https://github.com/emeeks/semiotic/issues/70
1115semiotic <- htmlDependency(
1216 name = " semiotic" ,
1317 version = " 1.2.4" ,
1418 src = c(href = " https://rawgit.com/timelyportfolio/semiotic/standalone/dist" ),
1519 script = " semiotic.js"
1620)
1721
22+ # original data was in wide format
23+ dotwide <- data.frame (
24+ region = c(" Developed regions" , " Developing regions" , " Northern Africa" , " Sub-Saharan Africa" , " Latin America and the Caribbean" , " Caucasus and Central Asia" , " Eastern Asia" , " Eastern Asia excluding China" , " Southern Asia" , " Southern Asia excluding India" , " South-eastern Asia" , " Western Asia" , " Oceania" , " World" ),
25+ y1990 = c(7.6 , 36.4 , 30 , 45.5 , 22.1 , 25.7 , 24.5 , 11.6 , 50.6 , 49.3 , 27.4 , 27.5 , 26.3 , 33.3 ),
26+ y2013 = c(3.4 , 22 , 13.3 , 31.1 , 9.2 , 14.8 , 7.7 , 7.5 , 29.5 , 30.1 , 14.4 , 13.7 , 21.3 , 20 ),
27+ stringsAsFactors = FALSE
28+ )
29+
30+ # convert to long format in R rather than JavaScript
31+ dotlong <- gather(dotwide , type , value , - region )
32+
1833dotplot <- tags $ script(HTML(babel_transform(
19- '
34+ sprintf( '
2035const colors = {
2136 y1990: "#00a2ce",
2237 y2013: "#4d430c"
2338};
2439
2540const dotRadius = 8;
2641
27- const baseData = [
28- { region: "Developed regions", y1990: 7.6, y2013: 3.4 },
29- { region: "Developing regions", y1990: 36.4, y2013: 22 },
30- { region: "Northern Africa", y1990: 30, y2013: 13.3 },
31- { region: "Sub-Saharan Africa", y1990: 45.5, y2013: 31.1 },
32- { region: "Latin America and the Caribbean", y1990: 22.1, y2013: 9.2 },
33- { region: "Caucasus and Central Asia", y1990: 25.7, y2013: 14.8 },
34- { region: "Eastern Asia", y1990: 24.5, y2013: 7.7 },
35- { region: "Eastern Asia excluding China", y1990: 11.6, y2013: 7.5 },
36- { region: "Southern Asia", y1990: 50.6, y2013: 29.5 },
37- { region: "Southern Asia excluding India", y1990: 49.3, y2013: 30.1 },
38- { region: "South-eastern Asia", y1990: 27.4, y2013: 14.4 },
39- { region: "Western Asia", y1990: 27.5, y2013: 13.7 },
40- { region: "Oceania", y1990: 26.3, y2013: 21.3 },
41- { region: "World", y1990: 33.3, y2013: 20 }
42- ];
43-
44- const data = [
45- ...baseData.map(d => ({ region: d.region, type: "y1990", value: d.y1990 })),
46- ...baseData.map(d => ({ region: d.region, type: "y2013", value: d.y2013 }))
47- ];
42+ const baseData = %s
43+
44+ const data = %s;
4845
4946const lineAnnotations = baseData.map(d => Object.assign({ type: "range" }, d));
5047
@@ -95,7 +92,10 @@ const dotplot =
9592/>
9693
9794ReactDOM.render(dotplot, document.body)
98- '
95+ ' ,
96+ jsonlite :: toJSON(dotwide , dataframe = " rows" ),
97+ jsonlite :: toJSON(dotlong , dataframe = " rows" )
98+ )
9999)))
100100
101101browsable(
0 commit comments