-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprac11.R
44 lines (39 loc) · 1.15 KB
/
prac11.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
41
42
43
44
library(tidyverse)
library(dslabs)
data("gapminder")
#time series plots
gapminder %>%
filter(country=='United States') %>%
ggplot(aes(year,fertility)) +
geom_point()
gapminder %>%
filter(country=='United States') %>%
ggplot(aes(year,fertility)) +
geom_line()
#for two countries
countries <- c('South Korea','Germany')
gapminder %>%
filter(country %in% countries) %>%
ggplot(aes(year,fertility)) +
geom_line()
#this does not specify we need two separate lines
#to do this we do
gapminder %>%
filter(country %in% countries) %>%
ggplot(aes(year,fertility,group = country)) +
geom_line()
#here we cant differentiate b/w the countries
#so we add color and by default we get two separate lines
gapminder %>%
filter(country %in% countries) %>%
ggplot(aes(year,fertility,col = country)) +
geom_line()
#legend is automatically added as well
#if we want to label then:
labels <- data.frame(country=countries,x=c(1975,1965),y=c(60,72))
gapminder %>%
filter(country %in% countries) %>%
ggplot(aes(year,life_expectancy,col = country)) +
geom_line() +
geom_text(data=labels,aes(x,y,label=country),size=5) +
theme(legend.position = 'none')