113 | The map is interactive in that you can click on
114 | anywhere within a state to see more detailed
115 | results about the voting in that state.
116 |
149 |
150 |
--------------------------------------------------------------------------------
/FollowOnNotes:
--------------------------------------------------------------------------------
1 | Plots aren't supposed to be quick to understand.
2 |
3 | And they shouldn't be simple to create.
4 |
5 | Turn tables into plots.
--------------------------------------------------------------------------------
/GNUmakefile:
--------------------------------------------------------------------------------
1 | ifndef DYN_DOCS
2 | DYN_DOCS=$(HOME)/Classes/StatComputing/XDynDocs/inst
3 | endif
4 |
5 | include $(DYN_DOCS)/Make/Makefile
6 |
--------------------------------------------------------------------------------
/GraphicsPartI.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dsidavis/Visualization/7b595a9f8b2671504ead46db32f103520f9b0d44/GraphicsPartI.pdf
--------------------------------------------------------------------------------
/Interactivity.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | High-level Concepts of Interactive and Web Graphics
High-level Concepts of Interactive and Web Graphics
DuncanTemple Lang
University of California at Davis Department of Statistics
4 | Goals of the session are
5 |
to introduce you to a variety of tools that you can use immediately to create interesting displays, dashboards, etc.
to explain the architecture involved so that you can go further than simple use of the tools
6 |
7 | These tools provide "instant" gratification (once you learn the basics).
8 | However, it is very important that you focus on using the tools to present the data clearly
9 | and offer insight for the viewer. It is easy to produce bad displays, and to focus on the "glossy", "moving"
10 | things.
11 |
12 | Interactive displays are very different from static plots.
13 | When we create a static plot, we make decisions about what is in the plot
14 | or not, what to emphasize. We are in charge of what the viewer sees.
15 | For an interactive plot, we still get to make many decisions
16 | that limit what the viewer can see. However, when the viewer
17 | sees the display, she can change it via the user controls we provide.
18 | We are providing the viewer with a process for exploring the information
19 | in the plot in her own way.
20 |
21 | Interactive plots are verging on software, and many are full-fledged
22 | pieces of software. Therefore, we need to incorporate best practices
23 | and considerations for both user interface (UI) and user experience
24 | (UX). We have seen best practices and considerations for static
25 | plots. These also (generally) apply to interactive plots, and we also
26 | have to consider dynamic, interactive best practices.
27 |
28 | We need to
29 |
consider what the viewer may want to do,
handle errors
provide feedback and suggestions
use clear interfaces with documentation. Often they will not be intuitive to everyone.
30 |
31 | There are many ways to create interactive plots. It is somewhat of a
32 | wild-west out there. Things are converging and approaches are being
33 | integrated. There are still a lot of tradeoffs. While many of you
34 | will want to quickly create standard plots, others will want to create
35 | non-standard plots and will have to work harder as there may not be
36 | existing functions to create those plots. Regardless, it is helpful,
37 | if not very important, to understand the fundamentals of the
38 | mechanisms that make all of this possible and to be able to go below
39 | the high-level interfaces.
40 |
<aside>
41 | I'm a big believer in minimizing the discontinuity in programming when dealing with problems.
42 | In other words, I don't want to have a situation where it is easy
43 | to do one thing, but a slight variation in that means an entirely different approach and
44 | having to learn a new software system or computational model.
45 | For this reason, I like to know how things work and be able to use the primitives
46 | when we need to do something slightly outside of the norm.
47 | </aside>
48 | There are (at least) three differerent styles of interactive plots:
49 | 1) stand-alone displays that contain all the information for their own interactivity (e.g. tooltips, animation in SVG)
50 | 2) displays that have client-side (JavaScript) code which updates the plot at viewing time
51 | 3) displays that need computations to be done at viewing time that can't be done in the client's browser, e.g. need to come back to R.
52 |
53 | When we are on our own machine, we don't need to care much about these distinctions.
54 | When we publish displays for other people to view, we have to consider some issues.
55 |
56 | If we are displaying data that cannot be explicitly shared in totality with viewers (for confidentiality reason or simply size of the
57 | data), but we can show summary plots, then we have to have any computations that update the display done on a server, not in each client's browser.
58 |
59 |
60 | The server does not run arbitrary code, but there are security issues that we need to be aware of.
61 | Running R on a server requires some care to ensure that people cannot inject code to expose information
62 | on the server, or delete files, or simply keeps the server busy so that other requests cannot be processed.
63 | If you build something popular, the demands on the server may be many.
64 | For personal use, or internally within an institution, this is probably not an issue.
65 |
66 | The more we can do in the client's browser, the lower the latency/delay waiting for results.
67 | Perhaps, the initial display of the page is delayed however.
68 | Ideally, display the initial page rapidly and asynchronously download additional elements
69 | we need (e.g. data for further plots).
70 |
71 | We're going to look under the hood so that you can learn how
72 | you can go further than the basics.
73 |
74 | Different Architectures for Interactive Plots
75 |
Use an R graphics device with locator() or setGraphicsEventHandlers()
PNG/JPEG files and image maps (very old)
Create plots in R to, e.g., SVG, with annotations to provide event handlers, animations.
76 |
RSVGTipsDevice
svg() graphics device and then post-process the SVG content to add tooltips, animations, event handlers - SVGAnnotation
Add SVG content to R objects in grid plot and generate SVG - gridSVG
77 |
Within R, create JavaScript, HTML code that will create the plot in the Web browser when loaded
Create HTML document whose sub-contents will be updated at
78 |
79 | Creating object-based pots where the elements in the plot is quite different
80 | from the R style of graphics.
81 | We can change the characteristics of an element and it will be immediately updated.
82 |
83 | Object-based displays are problematic as the number of elements grows.
84 | This is true of vectorized plots also.
85 | Instead of having a fixed number of pixels based on the dimensions
86 | of the raster image, object-based plots have as many elements as
87 | there are observations (or more).
88 |
89 | If you know R, it may be easier to create HTML, JavaScript code, etc. in R.
90 | Programmatically generating content is a good idea when it removes repetition
91 | (e.g. creating checkboxes for 100 senators) or we want to reproduce this in different ways.
92 | However, it adds an additional layer between the output we create and the input that creates it.
93 | This can make it difficult to create the final document we actually want.
94 | Furthermore, it often complicates debugging both the page generation and also
95 | the run-time behavior of the page. This is because we have to fully understand
96 | how and what the layer is generating.
97 |
98 | Client-server code is hard to debug since there are two agents involved.
99 | We can run the R shiny server interactively and catch errors.
100 |
170 |
--------------------------------------------------------------------------------
/Interactivity.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | High-level Concepts of Interactive and Web Graphics
5 |
6 | DuncanTemple Lang
7 | University of California at Davis
8 | Department of Statistics
9 |
10 |
11 |
12 |
13 |
14 |
15 | Goals of the session are
16 |
17 |
to introduce you to a variety of tools that you can use immediately to create interesting displays, dashboards, etc.
18 |
to explain the architecture involved so that you can go further than simple use of the tools
19 |
20 |
21 |
22 |
23 | These tools provide "instant" gratification (once you learn the basics).
24 | However, it is very important that you focus on using the tools to present the data clearly
25 | and offer insight for the viewer. It is easy to produce bad displays, and to focus on the "glossy", "moving"
26 | things.
27 |
28 |
29 |
30 | Interactive displays are very different from static plots.
31 | When we create a static plot, we make decisions about what is in the plot
32 | or not, what to emphasize. We are in charge of what the viewer sees.
33 | For an interactive plot, we still get to make many decisions
34 | that limit what the viewer can see. However, when the viewer
35 | sees the display, she can change it via the user controls we provide.
36 | We are providing the viewer with a process for exploring the information
37 | in the plot in her own way.
38 |
39 |
40 |
41 | Interactive plots are verging on software, and many are full-fledged
42 | pieces of software. Therefore, we need to incorporate best practices
43 | and considerations for both user interface (UI) and user experience
44 | (UX). We have seen best practices and considerations for static
45 | plots. These also (generally) apply to interactive plots, and we also
46 | have to consider dynamic, interactive best practices.
47 |
48 |
49 | We need to
50 |
51 |
consider what the viewer may want to do,
52 |
handle errors
53 |
provide feedback and suggestions
54 |
use clear interfaces with documentation. Often they will not be intuitive to everyone.
55 |
56 |
57 |
58 |
59 | There are many ways to create interactive plots. It is somewhat of a
60 | wild-west out there. Things are converging and approaches are being
61 | integrated. There are still a lot of tradeoffs. While many of you
62 | will want to quickly create standard plots, others will want to create
63 | non-standard plots and will have to work harder as there may not be
64 | existing functions to create those plots. Regardless, it is helpful,
65 | if not very important, to understand the fundamentals of the
66 | mechanisms that make all of this possible and to be able to go below
67 | the high-level interfaces.
68 |
69 |
70 |
78 |
79 |
80 |
81 | There are (at least) three differerent styles of interactive plots:
82 | 1) stand-alone displays that contain all the information for their own interactivity (e.g. tooltips, animation in SVG)
83 | 2) displays that have client-side (JavaScript) code which updates the plot at viewing time
84 | 3) displays that need computations to be done at viewing time that can't be done in the client's browser, e.g. need to come back to R.
85 |
86 |
87 |
88 | When we are on our own machine, we don't need to care much about these distinctions.
89 | When we publish displays for other people to view, we have to consider some issues.
90 |
91 |
92 |
93 | If we are displaying data that cannot be explicitly shared in totality with viewers (for confidentiality reason or simply size of the
94 | data), but we can show summary plots, then we have to have any computations that update the display done on a server, not in each client's browser.
95 | make this clearer about which computations need to be done on the server
96 |
97 |
98 |
99 | The server does not run arbitrary code, but there are security issues that we need to be aware of.
100 | Running R on a server requires some care to ensure that people cannot inject code to expose information
101 | on the server, or delete files, or simply keeps the server busy so that other requests cannot be processed.
102 | If you build something popular, the demands on the server may be many.
103 | For personal use, or internally within an institution, this is probably not an issue.
104 |
105 |
106 |
107 | The more we can do in the client's browser, the lower the latency/delay waiting for results.
108 | Perhaps, the initial display of the page is delayed however.
109 | Ideally, display the initial page rapidly and asynchronously download additional elements
110 | we need (e.g. data for further plots).
111 |
112 |
113 |
114 | We're going to look under the hood so that you can learn how
115 | you can go further than the basics.
116 |
117 |
118 |
119 |
120 | Different Architectures for Interactive Plots
121 |
122 |
Use an R graphics device with locator() or setGraphicsEventHandlers()
123 |
PNG/JPEG files and image maps (very old)
124 |
Create plots in R to, e.g., SVG, with annotations to provide event handlers, animations.
125 |
126 |
RSVGTipsDevice
127 |
svg() graphics device and then post-process the SVG content to add tooltips, animations, event handlers - SVGAnnotation
128 |
Add SVG content to R objects in grid plot and generate SVG - gridSVG
129 |
130 |
131 |
132 |
Within R, create JavaScript, HTML code that will create the plot in the Web browser when loaded
133 |
134 |
Create HTML document whose sub-contents will be updated at
135 |
136 |
137 |
138 |
139 | Creating object-based pots where the elements in the plot is quite different
140 | from the R style of graphics.
141 | We can change the characteristics of an element and it will be immediately updated.
142 |
143 |
144 |
145 | Object-based displays are problematic as the number of elements grows.
146 | This is true of vectorized plots also.
147 | Instead of having a fixed number of pixels based on the dimensions
148 | of the raster image, object-based plots have as many elements as
149 | there are observations (or more).
150 |
151 |
152 |
153 |
154 |
155 |
156 | If you know R, it may be easier to create HTML, JavaScript code, etc. in R.
157 | Programmatically generating content is a good idea when it removes repetition
158 | (e.g. creating checkboxes for 100 senators) or we want to reproduce this in different ways.
159 | However, it adds an additional layer between the output we create and the input that creates it.
160 | This can make it difficult to create the final document we actually want.
161 | Furthermore, it often complicates debugging both the page generation and also
162 | the run-time behavior of the page. This is because we have to fully understand
163 | how and what the layer is generating.
164 |
165 |
166 |
167 | Client-server code is hard to debug since there are two agents involved.
168 | We can run the R shiny server interactively and catch errors.
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 | http://timelyportfolio.github.io/gridSVG_intro/
177 |
178 |
179 | Linked plots
180 | Brushing
181 |
182 |
183 | animation
184 | Simple sequence of images
185 | Object-based animation.
186 |
187 |
188 |
189 | Basics of Stand-alone
190 | tooltips
191 | highlight (e.g. a point, a line)
192 |
193 |
194 | Off-The-Shelf Approaches
195 |
196 | googleVis
197 | https://developers.google.com/chart/
198 |
199 |
200 |
201 |
202 | Maps
203 | chloropleth maps. Good choice of colors vital.
204 |
205 | Google Earth
206 | allows the viewer to add/remove other elements/layers, control time window,
207 |
208 | RgoogleMaps
209 | ggmap
210 |
211 | rworldmap, rworldxtra
212 |
213 | par(mar = c(0, 0, 0, 0))
214 | plot(getMap("li"))
215 |
216 |
217 | plotKML package
218 |
219 |
220 | Linked maps
221 | file:///Users/duncan/Projects/NSFWorkshops/Visualization/maps/DistributionsMap.html
222 |
223 |
224 |
225 |
226 |
227 | HTML, CSS, JavaScript
228 | www.w3schools.com
229 |
230 |
231 |
232 | ExcitedRW: Click on a boxplot of timings, show code corresponding to that implementation.
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 | D3
241 | /Users/duncan/Projects/Visualization
242 |
243 |
244 |
245 |
--------------------------------------------------------------------------------
/JSEg/0_a1e99_9dabddb2_L.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dsidavis/Visualization/7b595a9f8b2671504ead46db32f103520f9b0d44/JSEg/0_a1e99_9dabddb2_L.jpg
--------------------------------------------------------------------------------
/JSEg/260px-Okapi2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dsidavis/Visualization/7b595a9f8b2671504ead46db32f103520f9b0d44/JSEg/260px-Okapi2.jpg
--------------------------------------------------------------------------------
/JSEg/440px-Lowland_Streaked_Tenrec,_Mantadia,_Madagascar.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dsidavis/Visualization/7b595a9f8b2671504ead46db32f103520f9b0d44/JSEg/440px-Lowland_Streaked_Tenrec,_Mantadia,_Madagascar.jpg
--------------------------------------------------------------------------------
/JSEg/Data.js:
--------------------------------------------------------------------------------
1 | var data = {
2 | "Hummingbird Moth": [ 'http://newsimg.bbc.co.uk/media/images/47868000/jpg/_47868651_001547179-1.jpg', "The hummingbird moth ...."],
3 | "Okapi" : [ "260px-Okapi2.jpg", "An Okapi is a type of" ],
4 | "Tenrec": ["440px-Lowland_Streaked_Tenrec,_Mantadia,_Madagascar.jpg", "Tenrecs are Wikipedia."]
5 | };
--------------------------------------------------------------------------------
/JSEg/Eg.js:
--------------------------------------------------------------------------------
1 | function toggleRightImage(obj)
2 | {
3 | toggleElement(document.getElementById('img2'));
4 | }
5 |
6 | function toggleElement(img)
7 | {
8 | console.log(img + " " + img.style);
9 | var style = img.style;
10 | if(style.length == 0 || style.display == 'inline')
11 | img.style.display = 'none';
12 | else
13 | img.style.display = 'inline';
14 | }
15 |
16 |
17 | function changeImage(obj)
18 | {
19 | var img = document.getElementById('img1');
20 | img.src = obj.value;
21 |
22 | if(data) {
23 | showAnimalText(obj.value);
24 | }
25 | }
26 |
27 | function showAnimalText(img)
28 | {
29 | var p = document.getElementById('announce')
30 | for(var key in data) {
31 | var obj = data[key];
32 | if(obj[0] == img) {
33 | alert('key ' + key + " " + obj[1]);
34 | p.innerHTML = obj[1];
35 | break;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/JSEg/eg.css:
--------------------------------------------------------------------------------
1 | .body {
2 | background: #FFF;
3 | margin-left: 3em;
4 | margin-right: 3em;
5 | font-family: Verdana, Arial, Helvetica, sans-serif;
6 | }
7 |
8 | div.note {
9 | border: black 1pt solid;
10 | background: lightgray;
11 | margin: 30px 30px 30px 30px;
12 | }
13 |
14 | .hidden {
15 | visibility: hidden;
16 | }
--------------------------------------------------------------------------------
/JSEg/jsAutoEg.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Example of JavaScript in HTML
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
Illustraing JavaScript Code in HTML
12 |
13 |
14 | This is very similar to the display in jsEg.html,
15 | but there are important differences.
16 |
17 |
We create the content of the pull-down menu programmatically.
18 |
When the viewer selects an animal, we display HTML text/content above the image.
19 |
We illustrate the alert() JavaScript function.
20 |
21 |
22 |
23 |
24 |
25 | We put information about each animal and its image into an "associative array"
26 | or named-element container in JavaScript.
27 | We have done this in an unintuitive manner with the text displayed in the optin as the key and then
28 | the information about the image and the text to show describing that animal.
29 | We should probably have used the file name/URL for the image as the key.
30 |
31 |
32 | When the animal changes, there is a relayout that resizes the two images and the layout of the page.
33 | This is a little jarring as the user interface controls move up or down.
34 | Similarly, this happens when we hide/show the right image.
35 | How can we fix this?
37 |
38 |
39 |
40 |
41 | We can make all the animal images the same size. We can do this manually outside of the Web page.
42 | Alternatively, we can set the width and height attributes of the IMG element in the HTML document.
43 |
44 |
We can use the visibility style with values visible and hidden. The latter causes the object to take up
45 | space but not be shown.
46 |
47 |
48 |
49 | The JavaScript code is stored in a separate file named Eg.js
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
61 |
62 |
63 |
64 |
71 |
72 |
81 |
82 |
83 |
84 | Duncan Temple Lang
85 | <duncan@r-project.org>
86 | Last modified: Sat Apr 25 05:06:59 PDT 2015
87 |
88 |
--------------------------------------------------------------------------------
/JSEg/jsEg.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Example of JavaScript in HTML
4 |
5 |
6 |
7 |
8 |
9 |
Illustraing JavaScript Code in HTML
10 |
11 |
12 | We create a simple HTML document that displays
13 | two images.
14 | The viewer can change the image on the left using a pull-down menu.
15 | She can hide and display the image on the right by toggling the checkbox.
16 |
17 |
18 | We create the HTML with a text editor.
19 | We'll display the two images in a table, but we could use CSS with float: left and float: right.
20 | The user-interface elements are within a form element, but this is not essential as we use
21 | JavaScript event handlers on each element.
22 | The two form elements are SELECT and an INPUT.
23 | We specify JavaScript a command(s) for the onchange attribute on each of these.
24 | The select element has several OPTION elements giving the items in the pull down menu.
25 | The value attribute of each OPTION gives the URL for the image, either a regular URL or a local
26 | file name. We use these as the value for the corresponding IMG element's src attribute.
27 |
28 |
29 | The JavaScript code is stored in a separate file named Eg.js
30 |
31 |
32 | The CSS file for this HTML document is in eg.css.
33 |