Skip to content

Commit

Permalink
First Version of the third case study
Browse files Browse the repository at this point in the history
  • Loading branch information
jingmiao7 committed Sep 17, 2024
1 parent c889b7f commit 020e943
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion week_03/case_study_03.R
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@

install.packages("gapminder")

library(ggplot2)
library(gapminder)
library(dplyr)

gapminder
str(gapminder)

NoK_gapminder <- gapminder %>%
filter(country != "Kuwait")

ggplot(NoK_gapminder, aes(x = lifeExp, y = gdpPercap, color = continent, size = pop/100000)) +
geom_point() +
theme_bw() +
scale_y_continuous(trans = "sqrt") +
facet_wrap(~year,nrow=1) +
labs(title = "Relationship between GDP and life expetation") +
xlab("Life Expection (Year)") +
ylab("GDP (million $)")

gapminder_weighted <- NoK_gapminder %>%
group_by(continent, year) %>%
summarize(gdpPercapweighted = weighted.mean(x = gdpPercap, w = pop), pop = sum(as.numeric(pop)))

ggplot() +
geom_line(data = NoK_gapminder, aes(x = year, y = gdpPercap, color = continent, group = country)) +
geom_point(data = NoK_gapminder, aes(x = year, y = gdpPercap, color = continent, group = country)) +
geom_line(data = gapminder_weighted, aes(x = year, y = gdpPercapweighted))+
geom_point(data = gapminder_weighted, aes(x = year, y = gdpPercapweighted, size = pop/100000)) +
facet_wrap(~continent,nrow=1) +
theme_bw() +
labs()

0 comments on commit 020e943

Please sign in to comment.