library(tidyverse)
library(openintro)
data('arbuthnot', package = 'openintro')arbuthnot$girls## [1] 4683 4457 4102 4590 4839 4820 4928 4605 4457 4952 4784 5332 5200 4910 4617
## [16] 3997 3919 3395 3536 3181 2746 2722 2840 2908 2959 3179 3349 3382 3289 3013
## [31] 2781 3247 4107 4803 4881 5681 4858 4319 5322 5560 5829 5719 6061 6120 5822
## [46] 5738 5717 5847 6203 6033 6041 6299 6533 6744 7158 7127 7246 7119 7214 7101
## [61] 7167 7302 7392 7316 7483 6647 6713 7229 7767 7626 7452 7061 7514 7656 7683
## [76] 5738 7779 7417 7687 7623 7380 7288
There are more likely to be trend in the number of girls over the years.The slope of the graph is significantly going high from the year 1660 through over the year 1700.
ggplot(data = arbuthnot, aes(x = year, y = girls)) + geom_point()ggplot(data = arbuthnot, aes(x = year, y = girls)) + geom_line()The ratio of boys born over years is widely fluctuating.
arbuthnot <- arbuthnot %>%
mutate(boy_ratio = boys/(boys + girls))
ggplot(data = arbuthnot, aes(x = year, y = boy_ratio)) + geom_line()All the years starting from 1940 to 2002. row = 63 and column = 3 column names are year, boys and girls.
glimpse(present)## Rows: 63
## Columns: 3
## $ year <dbl> 1940, 1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949, 1950…
## $ boys <dbl> 1211684, 1289734, 1444365, 1508959, 1435301, 1404587, 1691220, 1…
## $ girls <dbl> 1148715, 1223693, 1364631, 1427901, 1359499, 1330869, 1597452, 1…
present$year## [1] 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954
## [16] 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969
## [31] 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984
## [46] 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999
## [61] 2000 2001 2002
Insert any text here.
present <- present %>%
mutate(total = boys + girls)Insert any text here.
present <- present %>%
mutate(prop_boys = boys /total)
ggplot(data = present, aes(x = year, y = total)) + geom_point()ggplot(data = present, aes(x = year, y = prop_boys)) + geom_point()1961
present <- present %>%
arrange(desc(total))