Submit this file (after adding your name after “author”) and the knitted html (or pdf if you have a latex distribution installed in your computer) on Canvas. Make sure to label your plots!
dslabs and define the dataset
gapminder as gapminder <- as_tibble(gapminder). There is
another dataset called gapminder too, that is in the
package gapminder. They are different, so make sure you
only load dslabs. If you want to avoid confusion, you can
write dslabs::gapminder to make the package explicit.## Warning: package 'dslabs' was built under R version 4.2.3
gdp_per_cap corresponding
to gdp divided by population.gapminder <- mutate(gapminder, gdp_per_cap = gdp/population)
mean_pop, removing missing values and assigning the output
to a new object called gapminder_new.gapminder_new <- gapminder %>% group_by(continent,year) %>% filter(year<2016) %>% summarise(mean_pop = mean(population, na.rm = TRUE))
## `summarise()` has grouped output by 'continent'. You can override using the
## `.groups` argument.
ggplot(gapminder_new, aes(x=year,y=mean_pop/1000000, color=continent)) +ggtitle("World Population by Year and Continent in Millions") +xlab("Year") + ylab("Mean Population") + geom_line()
Call this graph g.
g <- ggplot(gapminder %>% filter(year==2014), aes(x=life_expectancy,color=continent)) + geom_histogram(color="white",binwidth=5,boundary=45,fill="#d90502") + labs(title="Life Expectancy in 2014",x="Life Expectancy Rate",y="Value")
g + facet_grid(
rows = vars(continent)
)
ggplot(gapminder %>% filter(year==2014),aes(x=infant_mortality,y=fertility)) + geom_point(size=3,alpha=0.5,color="#009E73",na.rm = TRUE) + scale_y_continuous() + labs(title="Fertility Rate by Infant Mortality in 2014", x="Infant Mortality Rate",y="Fertility Rate")