In this exercise you will learn to plot data using the ggplot2 package. To answer the questions below, use 4.1 Categorical vs. Categorical from Data Visualization with R.

## Loading required package: lubridate
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
## Loading required package: PerformanceAnalytics
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Registered S3 method overwritten by 'xts':
##   method     from
##   as.zoo.xts zoo
## 
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
## 
##     legend
## Loading required package: quantmod
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## Version 0.4-0 included new data defaults. See ?getSymbols.
## Loading required package: tidyverse
## ── Attaching packages ───────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.2.1     ✔ purrr   0.3.2
## ✔ tibble  2.1.3     ✔ dplyr   0.8.3
## ✔ tidyr   0.8.3     ✔ stringr 1.4.0
## ✔ readr   1.3.1     ✔ forcats 0.4.0
## ── Conflicts ──────────────────── tidyverse_conflicts() ──
## ✖ lubridate::as.difftime() masks base::as.difftime()
## ✖ lubridate::date()        masks base::date()
## ✖ dplyr::filter()          masks stats::filter()
## ✖ dplyr::first()           masks xts::first()
## ✖ lubridate::intersect()   masks base::intersect()
## ✖ dplyr::lag()             masks stats::lag()
## ✖ dplyr::last()            masks xts::last()
## ✖ lubridate::setdiff()     masks base::setdiff()
## ✖ lubridate::union()       masks base::union()
## # A tibble: 22,230 x 8
## # Groups:   symbol [3]
##    symbol date        open  high   low close   volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 AAPL   1990-01-02  1.26  1.34  1.25  1.33 45799600    1.08 
##  2 AAPL   1990-01-03  1.36  1.36  1.34  1.34 51998800    1.09 
##  3 AAPL   1990-01-04  1.37  1.38  1.33  1.34 55378400    1.10 
##  4 AAPL   1990-01-05  1.35  1.37  1.32  1.35 30828000    1.10 
##  5 AAPL   1990-01-08  1.34  1.36  1.32  1.36 25393200    1.11 
##  6 AAPL   1990-01-09  1.36  1.36  1.32  1.34 21534800    1.10 
##  7 AAPL   1990-01-10  1.34  1.34  1.28  1.29 49929600    1.05 
##  8 AAPL   1990-01-11  1.29  1.29  1.23  1.23 52763200    1.00 
##  9 AAPL   1990-01-12  1.22  1.24  1.21  1.23 42974400    1.00 
## 10 AAPL   1990-01-15  1.23  1.28  1.22  1.22 40434800    0.997
## # … with 22,220 more rows
## # A tibble: 90 x 3
## # Groups:   symbol [3]
##    symbol yearly.returns  year
##    <chr>           <dbl> <dbl>
##  1 AAPL           0.169   1990
##  2 AAPL           0.323   1991
##  3 AAPL           0.0691  1992
##  4 AAPL          -0.504   1993
##  5 AAPL           0.352   1994
##  6 AAPL          -0.173   1995
##  7 AAPL          -0.345   1996
##  8 AAPL          -0.371   1997
##  9 AAPL           2.12    1998
## 10 AAPL           1.51    1999
## # … with 80 more rows

Q1 Calculate mean yearly returns for each stock.

Hint: See the code in 4.3.1 Bar chart (on summary statistics).

Q2 Plot mean yearly returns using bar charts.

Hint: See the code in 4.3.1 Bar chart (on summary statistics).

Q3 Label the bars with mean yearly returns.

Hint: See the code in 4.3.1 Bar chart (on summary statistics).

## 
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
## 
##     discard
## The following object is masked from 'package:readr':
## 
##     col_factor

Q4 Plot the distribution of yearly returns by stock using kernel density plots.

Hint: See the code in 4.3.2 Grouped kernel density plots.

Q5 Which of the three stocks has highest chance of losing big when things go wrong? Discuss your reason.

Hint: Google how to interpret density plots.

Out of the three stocks IBM is losing the most. the other companies are more accurate with there average returns.

Q6 Plot the distribution of yearly returns by stock using boxplots.

Hint: See the code in 4.3.3 Box plots.

Q7 If you were a risk-loving investor (defined as one chasing after the greatest returns even at the risk of losing big), which of the three stocks would you choose? Discuss your reason.

I would choose microsoft because of the amount of outliars.

Q8 Hide the messages, but display the code and their results from the webpage.

Hint: Use message, echo and results in the global chunk options. Refer to the RMarkdown Reference Guide.

Q9 Display the title and your name correctly at the top of the webpage.

Q10 Use the correct slug.