visualization basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...every geom has a position...
TRANSCRIPT
![Page 1: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/1.jpg)
Visualization Basics!Part II!
![Page 2: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/2.jpg)
position adjustments
![Page 3: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/3.jpg)
Every geom has a position argument that controls how the object is placed in the plot
movies %>% mutate(fresh = critics_score >= 75) %>% ggplot(aes(mpaa_rating, fill = fresh)) + geom_bar()
![Page 4: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/4.jpg)
Every geom has a position argument that controls how the object is placed in the plot
movies %>% mutate(fresh = critics_score >= 75) %>% ggplot(aes(mpaa_rating, fill = fresh)) + geom_bar(position = “fill”)
![Page 5: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/5.jpg)
Your Turn 8Make the plot below by adjusting the position argument of geom_bar. See the help file (?geom_bar).
![Page 6: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/6.jpg)
movies %>% mutate(fresh = critics_score >= 75) %>% ggplot(aes(mpaa_rating, fill = fresh)) + geom_bar(position = “dodge”)
![Page 7: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/7.jpg)
movies %>% mutate(audience_rded = round(audience_score, -1), critics_rded = round(critics_score, -1)) %>% ggplot(aes(audience_rded, critics_rded)) + geom_point()
Also, geom_point has a useful position adjustment. When points appear on a grid, there might be several points being plotted on top of one another.
![Page 8: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/8.jpg)
movies %>% mutate(audience_rded = round(audience_score, -1), critics_rded = round(critics_score, -1)) %>% ggplot(aes(audience_rded, critics_rded)) + geom_point(position = “jitter”)
Jitter adds a small amount of random change to the position of each point.
![Page 9: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/9.jpg)
movies %>% mutate(audience_rded = round(audience_score, -1), critics_rded = round(critics_score, -1)) %>% ggplot(aes(audience_rded, critics_rded)) + geom_jitter(width = 1, height = 1)
geom_jitter is geom_point with position set to jitter. It makes it easier to control the amount of jittering using width and height
![Page 10: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/10.jpg)
Your Turn 9Add a geom_jitter layer to a boxplot to make the plot below.
![Page 11: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/11.jpg)
ggplot(movies,aes(mpaa_ra1ng,cri1cs_score))+geom_boxplot(outlier.color=“red”)+geom_ji?er(height=0,alpha=0.5,size=0.75)
![Page 12: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/12.jpg)
coordinate systems
![Page 13: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/13.jpg)
ggplot(movies, aes(audience_score, critics_score)) + geom_point()
The default coordinate system is the Cartesian coordinate system, where x and y act independently
![Page 14: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/14.jpg)
ggplot(movies, aes(audience_score, critics_score)) + geom_point() + coord_fixed()
coord_fixed locks x and y with a certain ratio (default is 1).
![Page 15: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/15.jpg)
ggplot(map_data("italy"), aes(long, lat, group = group)) + geom_polygon(fill = "white", color = "black")
Aspect ratio is important for spatial data.
![Page 16: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/16.jpg)
ggplot(map_data("italy"), aes(long, lat, group = group)) + geom_polygon(fill = "white", color = "black") + coord_quickmap()
Aspect ratio is important for spatial data.
![Page 17: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/17.jpg)
ggplot(movies, aes(genre)) + geom_bar()
Flipping coordinates is helpful for bar plots and boxplots.
![Page 18: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/18.jpg)
ggplot(movies, aes(genre)) + geom_bar() + coord_flip()
Flipping coordinates is helpful for bar plots and boxplots.
![Page 19: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/19.jpg)
ggplot(movies, aes(mpaa_rating, fill = mpaa_rating)) + geom_bar(width = 1, show.legend = FALSE)
The other most common coordinate system is polar coordinates
![Page 20: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/20.jpg)
ggplot(movies, aes(mpaa_rating, fill = mpaa_rating)) + geom_bar(width = 1, show.legend = FALSE) + coord_polar()
This leads to a Coxcomb plot
![Page 21: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/21.jpg)
grammar of graphics
![Page 22: Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position argument that controls how the object is placed in the plot movies %>% mutate(fresh](https://reader034.vdocuments.mx/reader034/viewer/2022042412/5f2aff90d55a287a7815ee95/html5/thumbnails/22.jpg)
ggplot(data = <DATA>) + <GEOM_FUNCTION>( mapping = aes(<MAPPINGS>), stat = <STAT>, position = <POSITION> ) + <COORDINATE_FUNCTION> + <FACET_FUNCTION>
This is not only a template for the most common named plots (scatterplot, bar plot, etc.), but also a template for any plot.
A Grammar of Graphics