Hans Rosling is one of the most popular data scientists on the web. His original TED talk was very popular among my friends when it came out. We are going to create some graphics using his formatted data as our weekly case study. Note that we need to remove Kuwait from the data (discussion on this)
[X] Recreate the two graphics shown below using gapminder dataset from library(gapminder) (get them to match as closely as you can)
[X] Build an Rmd file that has the following features
[X] Save your .Rmd, .md, and the two .png’s of the plots into your git repository.
I was able to learn a few different things in this case study. I was able to learn what how to use different data sets in ggplot. I learned how to use filter functions. I was also able to learn how group by and weighted mean.
gapminder %>%
filter(country != "Kuwait") %>%
ggplot(mapping = aes(x=lifeExp, y=gdpPercap)) +
geom_point(mapping = aes(x=lifeExp, y=gdpPercap, color=continent, size=pop/100000)) +
facet_wrap(~ year, nrow=1) +
scale_y_continuous(trans = "sqrt") +
labs(x = "Life Expectancy", y="GDP per capita",color = "Continent", size = "Population (100k)")
ggsave("case_study2a.png", width = 15, units = "in")
## Saving 15 x 6 in image
weight <- gapminder %>%
group_by(continent, year) %>%
mutate(w.mean=weighted.mean(x=gdpPercap, w=pop))
gapminder %>%
filter(country != "Kuwait") %>%
ggplot(aes(x=year, y=gdpPercap)) +
geom_line(aes(group=country, color=continent)) +
geom_point(aes(color=continent, size=pop/40000)) +
geom_point(data=weight, aes(x=year, y=w.mean, size=pop/40000), color="black") +
geom_line(data=weight, aes(x=year, y=w.mean), color="black") +
facet_wrap(~ continent, nrow=1) +
theme_bw() +
labs(y="GDP per capita", color="Continent", size="Population (100k)")
ggsave("case_study2b.png", width = 15, units = "in")
## Saving 15 x 6 in image