Chapter 4 create a bubble plot
ggplot(data = gdp, mapping = aes(x = gdpPercap, y = lifeExp, size = pop, fill = continent)) + geom_point(alpha = 0.5, shape = 21, color = “black”) + scale_size(range = c(.1, 24), name = “Population (M)”) + theme_minimal() + theme(legend.position = “right”) + labs( subtitle = “Life Expectancy vs. GDP per Capita,” y = “Life Expectancy,” x = “GDP per Capita,” title = “Scatter Plot,” caption = “Source: gapminder” )
#Quiz 4-1
gdp <- gapminder %>%
filter(year==“2007”) %>%
dplyr::select(-year) %>%
arrange(desc(pop)) %>%
mutate(country = factor(country, country))
ggplot(data = gdp, aes(x = lifeExp, fill = continent)) + geom_histogram()
#Quiz 4-2
ggplot(data = gdp, aes(x = lifeExp, fill = continent)) + geom_histogram() + facet_grid(cols = vars(colors))