#step 1 Import Data
setwd("~/NYU/classes/2. R/Assignments/Lesson 5")
library(readr)
le <- read_csv("life_expectancy.csv")
## Rows: 264 Columns: 60
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (2): Country Name, Country Code
## dbl (57): 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, ...
## lgl (1): 2017
##
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(le)
gdp <- read_csv("gdp.csv")
## Rows: 264 Columns: 60
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (2): Country Name, Country Code
## dbl (58): 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, ...
##
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(gdp)
#Step #2 - merging the data
country= gdp$`Country Name`
gdp2016= gdp$`2016`/1000000000000
le2016=le$`2016`
#step #3 create a new data frame
gdp_le <- data.frame(country,gdp2016,le2016)
View(gdp_le)
#step # 4 create a scatter plot
plot(gdp_le$gdp2016, gdp_le$le2016)
#step 5 - refine the plot
#same plot function,
#add x axis title,
#add y axis title (ylab=y lable),
#main = chart title,
#remove the box (frame.plot),
#change color (col=),
#lastly set limits 0 - 100. (the last figure looks to be out of the parameters)
plot(gdp_le$gdp2016, gdp_le$le2016, xlab="GDP (in trillions of USD)", ylab="Life expectancy", main = "GDP and life expectancy in 2016 by country", frame.plot = FALSE, col="#4cbea3", xlim=c(min=0, max=100))
#Task #2 - Create a histogram of GDP
hist(gdp_le$gdp2016, main = "GDP in 2016 by country", xlab = "GDP (in trillions of USD)", col="red", breaks=10)
#Task #3a: Create a box ans whisker xplot of Life Expectancy
boxplot(gdp_le$le2016, main = "Life expectancy in 2016 by country", xlab = "Life expectancy", ylab = "Age", col="green")