+ All Categories
Home > Documents > Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position...

Visualization Basicswebspace.ship.edu/lebryant/mat219/pdf/slides-09-vis...Every geom has a position...

Date post: 07-Jul-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
22
Visualization Basics Part II
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


Recommended