-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_plot.R
40 lines (32 loc) · 1.03 KB
/
example_plot.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
## Vincent Major
## August 2020
## run:
# > setwd('/work')
# > install.packages('packrat')
# > packrat::restore('/work')
# and then proceed
.libPaths()
packrat::on("/work")
.libPaths()
library(ggplot2)
library(dplyr)
## simple ggplot from gapminder data for example
gapminder = gapminder::gapminder
gapminder %>%
filter(year == 2007) %>%
ggplot(aes(x = lifeExp, y = gdpPercap,
color = continent, size = pop)) +
geom_point()
gapminder %>%
filter(year == 1957 | year == 2007) %>%
arrange(year) %>%
group_by(country) %>%
mutate(`% Difference in GDP per capita` = (gdpPercap - lag(gdpPercap))*100/lag(gdpPercap),
`% Difference in Population` = (pop - lag(pop))*100/lag(pop),
`% Difference in Life Expectancy` = (lifeExp - lag(lifeExp))*100/lag(lifeExp) ) %>%
filter(year == 2007) %>%
ggplot(aes(x = `% Difference in Population`,
y = `% Difference in Life Expectancy`,
color = continent,
size = `% Difference in GDP per capita` )) +
geom_point()