19 Critique
-
Upload
hadley-wickham -
Category
Technology
-
view
126 -
download
4
description
Transcript of 19 Critique
![Page 1: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/1.jpg)
Hadley Wickham
Stat405Graphical theory & critique
Monday, 2 November 2009
![Page 2: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/2.jpg)
Exploratory graphics
Are for you (not others). Need to be able to create rapidly because your first attempt will never be the most revealing.
Iteration is crucial for developing the best display of your data.
Gives rise to two key questions:
Monday, 2 November 2009
![Page 3: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/3.jpg)
What should I plot?How can I plot it?
Monday, 2 November 2009
![Page 4: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/4.jpg)
Two general tools
Plot critique toolkit: “graphics are like pumpkin pie”
Theory behind ggplot2:“A layered grammar of graphics”
plus lots of practice...
Monday, 2 November 2009
![Page 5: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/5.jpg)
Graphics are like pumpkin pie
The four C’s of critiquing a graphic
Monday, 2 November 2009
![Page 6: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/6.jpg)
Content
Monday, 2 November 2009
![Page 7: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/7.jpg)
Construction
Monday, 2 November 2009
![Page 8: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/8.jpg)
ContextMonday, 2 November 2009
![Page 9: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/9.jpg)
ConsumptionMonday, 2 November 2009
![Page 10: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/10.jpg)
Content
What data (variables) does the graph display?What non-data is present?What is pumpkin (essence of the graphic) vs what is spice (useful additional info)?
Monday, 2 November 2009
![Page 11: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/11.jpg)
Your turn
Identify the data and non-data on “Napoleon's march” and “Building an electoral victory”. Which features are the most important? Which are just useful background information?
Monday, 2 November 2009
![Page 12: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/12.jpg)
Results
Minard’s march: (top) latitude, longitude, number of troops, direction, branch, city name (bottom) latitude, temperature, dateBuilding an electoral victory: state, number of electoral college votes, winner, margin of victory
Monday, 2 November 2009
![Page 13: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/13.jpg)
Construction
How many layers are on the plot?What data does each layer display? What sort of geometric object does it use? Is it a summary of the raw data? How are variables mapped to aesthetics?
Monday, 2 November 2009
![Page 14: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/14.jpg)
Perceptual mapping1. Position along a common scale 2. Position along nonaligned scale 3. Length4. Angle/slope5. Area 6. Volume7. Colour
Best
Worst
For continuous
variables only!
Monday, 2 November 2009
![Page 15: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/15.jpg)
Your turn
Answer the following questions for “Napoleon's march” and “Flight delays”:How many layers are on the plot?What data does the layer display? How does it display it?
Monday, 2 November 2009
![Page 16: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/16.jpg)
ResultsNapoleon’s march: (top) (1) path plot with width mapped to number of troops, colour to direction, separate group for each branch (2) labels giving city names (bottom) (1) line plot with longitude on x-axis and temperature on y-axis (2) text labels giving datesFlight delays: (1) white circles showing 100% cancellation, (2) outline of states, (3) points with size proportional to percent cancellations at each airport.
Monday, 2 November 2009
![Page 17: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/17.jpg)
Can the explain composition of a graphic in words, but how do we
create it?
Monday, 2 November 2009
![Page 18: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/18.jpg)
“If any number of magnitudes are each the same multiple of the same number of other magnitudes, then the sum is that multiple of the sum.” Euclid, ~300 BC
Monday, 2 November 2009
![Page 19: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/19.jpg)
“If any number of magnitudes are each the same multiple of the same number of other magnitudes, then the sum is that multiple of the sum.” Euclid, ~300 BC
m(Σx) = Σ(mx)Monday, 2 November 2009
![Page 20: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/20.jpg)
The grammar of graphics
An abstraction which makes thinking about, reasoning about and communicating graphics easier.
Developed by Leland Wilkinson, particularly in “The Grammar of Graphics” 1999/2005
You’ve been using it in ggplot2 without knowing it! But to do more, you need to learn more about the theory.
Monday, 2 November 2009
![Page 21: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/21.jpg)
What is a layer?
• Data
• Mappings from variables to aesthetics (aes)
• A geometric object (geom)
• A statistical transformation (stat)
• A position adjustment (position)
Monday, 2 November 2009
![Page 22: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/22.jpg)
layer(geom, stat, position, data, mapping, ...)
layer( data = mpg, mapping = aes(x = displ, y = hwy), geom = "point", stat = "identity", position = "identity")
layer( data = diamonds, mapping = aes(x = carat), geom = "bar", stat = "bin", position = "stack")
Monday, 2 November 2009
![Page 23: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/23.jpg)
# A lot of typing!
layer( data = mpg, mapping = aes(x = displ, y = hwy), geom = "point", stat = "identity", position = "identity")
# Every geom has an associated default statistic# (and vice versa), and position adjustment.
geom_point(aes(displ, hwy), data = mpg)geom_histogram(aes(displ), data = mpg)
Monday, 2 November 2009
![Page 24: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/24.jpg)
# To actually create the plotggplot() + geom_point(aes(displ, hwy), data = mpg) ggplot() + geom_histogram(aes(displ), data = mpg)
Monday, 2 November 2009
![Page 25: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/25.jpg)
# Multiple layersggplot() + geom_point(aes(displ, hwy), data = mpg) + geom_smooth(aes(displ, hwy), data = mpg)
# Avoid redundancy:ggplot(mpg, aes(displ, hwy)) + geom_point() + geom_smooth()
Monday, 2 November 2009
![Page 26: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/26.jpg)
# Different layers can have different aestheticsggplot(mpg, aes(displ, hwy)) + geom_point(aes(colour = class)) + geom_smooth()
ggplot(mpg, aes(displ, hwy)) + geom_point(aes(colour = class)) + geom_smooth(aes(group = class), method = "lm", se = F)
Monday, 2 November 2009
![Page 27: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/27.jpg)
Your turnFor each of the following plots created with qplot, recreate the equivalent ggplot code.
qplot(price, carat, data = diamonds)
qplot(hwy, cty, data = mpg, geom = "jitter")
qplot(reorder(class, hwy), hwy, data = mpg, geom = c("jitter", "boxplot"))
qplot(log10(price), log10(carat), data = diamonds), colour = color) + geom_smooth(method = "lm")
Monday, 2 November 2009
![Page 28: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/28.jpg)
ggplot(diamonds, aes(price, data)) + geom_smooth()
gglot(mpg, aes(hwy, cty)) + geom_jitter()
ggplot(mpg, aes(reorder(class, hwy), hwy)) + geom_jitter() + geom_boxplot()
ggplot(diamonds, aes(log10(price), log10(carat), colour = color)) + geom_point() + geom_smooth(method = "lm")
Monday, 2 November 2009
![Page 29: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/29.jpg)
More geoms & stats
See http://had.co.nz/ggplot2 for complete list with helpful icons:
Geoms: (0d) point, (1d) line, path, (2d) boxplot, bar, tile, text, polygon
Stats: bin, summary, sum
Monday, 2 November 2009
![Page 30: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/30.jpg)
Go back to the descriptions of “Minard’s march” and “Flight delays” that you created before. Start converting your textual description in to working ggplot2 code. Use the data sets available on line to produce the graphics.
Your turn
Monday, 2 November 2009
![Page 31: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/31.jpg)
Other featuresScales. Used to override default perceptual mappings. Mainly useful for polishing plot for communication.
Coordinate system. Rarely useful, but when needed are critical.
Facetting. Have seen in use already. Only other feature of importance is interaction with scales.
Themes: control presentation of non-data elements.
Monday, 2 November 2009
![Page 32: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/32.jpg)
Project 3 preview
Choose your own dataset.
Results will be presented as poster during a formal poster session in the last week of class.
On November 16, Tracey Volz (a communications expert) will come and talk about how to create a good poster
Monday, 2 November 2009
![Page 33: 19 Critique](https://reader034.fdocuments.net/reader034/viewer/2022050920/54c662f84a79591e088b45a8/html5/thumbnails/33.jpg)
Data suggestions
http://delicious.com/hadley/data
http://github.com/hadley/data-housing-crisis
Monday, 2 November 2009