visualization basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-i-part1.pdfpart i!...
TRANSCRIPT
![Page 1: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/1.jpg)
Visualization Basics!Part I!
![Page 2: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/2.jpg)
"The simple graph has brought more information to the data analyst’s mind than any other device.”
-John Tukey
![Page 3: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/3.jpg)
A Grammar of Graphics
A small, concise language to describe the components of a graphic.
We can move beyond named graphics (e.g. scatterplot) and gain a deeper understanding.
www.gapminder.org
![Page 4: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/4.jpg)
mpg dataset
![Page 5: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/5.jpg)
Question
Confer with your group.
What relationship do you expect to see between engine size (displ) and mileage (hwy)?
![Page 6: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/6.jpg)
Your Turn #1
Write and run this code in your script to make a graph. Pay strict attention to spelling, capitalization, and parentheses! ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy))
![Page 7: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/7.jpg)
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy))
![Page 8: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/8.jpg)
1. “Ini1alize”aplotwithggplot()2. Addlayerswithgeom_func1ons ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy))
![Page 9: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/9.jpg)
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy))
data +beforenewline
typeoflayer aes() xvariable yvariable
![Page 10: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/10.jpg)
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy))
A Template ggplot(data = <DATA>) + <GEOM_FUNCTION>(mapping = aes(<MAPPINGS>))
![Page 11: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/11.jpg)
Mappings
![Page 12: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/12.jpg)
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy))
WhydothesecarsgetbeEergasmileage?
![Page 13: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/13.jpg)
Aesthetics
size shape color
![Page 14: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/14.jpg)
Visual Space Data Spacecolor classredbrowngreenaquabluevioletpink
2seatercompactmidsizeminivanpickupsubcompactsuv
![Page 15: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/15.jpg)
Aesthetics
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy, color = class))
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy, size = class))
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy, shape = class))
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy, alpha = class))
aesthe1cproperty
variabletomapitto
![Page 16: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/16.jpg)
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy, color = class))
Legendaddedautoma1cally
![Page 17: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/17.jpg)
Your Turn 2ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy)) In your script, edit the code above by adding color, size,alpha, and shape aesthetics your graph. Experiment.
Do different things happen when you map aesthetics to categorical and numerical variables?
What happens when you add more aesthetics?
![Page 18: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/18.jpg)
Color
Size
Shape
Categorical Numerical
![Page 19: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/19.jpg)
Set vs. Map
![Page 20: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/20.jpg)
Howcanwemakethisplot?
![Page 21: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/21.jpg)
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy, color = class))
Insidetheaes()mapsthe
aesthe1ctoavariable
![Page 22: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/22.jpg)
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy), color = “blue”)
Outsidetheaes()setstheaesthe1ctoa
value
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy, color = class))
![Page 23: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/23.jpg)
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy, color = class))
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy), color = “blue”)
![Page 24: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/24.jpg)
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy, color = “blue”))
Uh-oh!Thisshouldbe
movedoutsideaes()
![Page 25: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/25.jpg)
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy), color = class)
Uh-oh!Thisshouldbe
movedinsideaes()
Errormessagescanbeweird.Inthiscase,classhasanothermeaninginRthat
leadstothiserror.
![Page 26: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/26.jpg)
Geoms
![Page 27: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/27.jpg)
How are these plots similar?
![Page 28: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/28.jpg)
How are these plots similar?
The x variable, y variable, and data
![Page 29: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/29.jpg)
How are these plots different?
![Page 30: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/30.jpg)
How are these plots different?
The geometric object (geom). This is the visual object used to represent the data.
![Page 31: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/31.jpg)
geoms
ggplot(data = <DATA>) + <GEOM_FUNCTION>(mapping = aes(<MAPPINGS>))
![Page 32: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/32.jpg)
geom_functions
Each geom_function requires a mapping
argument
![Page 33: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/33.jpg)
geom_ function aestheticsEach geom_ function has
aesthetics that can be mapped to variables, or set to values.
Some aesthetics are required. The rest are optional
{
![Page 34: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/34.jpg)
Your Turn 3Withyourpartner,decidehowtoreplacethisscaEerplotwithonethatdrawsboxplots.Usethecheatsheet.Tryyourbestguess.
ggplot(data = mpg) + geom_point(mapping = aes(x = class, y = hwy))
![Page 35: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/35.jpg)
ggplot(data = mpg) + geom_boxplot(mapping = aes(x = displ, y = hwy))
![Page 36: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/36.jpg)
Your Turn 4Withyourpartner,makethehistogramofhwybelow.Usethecheatsheet.Hint:donotsupplyayvariable.
![Page 37: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/37.jpg)
ggplot(data = mpg) + geom_histogram(mapping = aes(x = hwy))
![Page 38: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-02-vis-basics-I-part1.pdfPart I! "The simple graph has brought more ... -John Tukey. A Grammar of Graphics A small,](https://reader030.vdocuments.site/reader030/viewer/2022040318/5e34083fdfd57b178321b687/html5/thumbnails/38.jpg)
ggplot(data = mpg) + geom_histogram(mapping = aes(x = hwy), binwidth = 2)