Ken Lew
4/23/2021
Video Presentation: https://youtu.be/r0bgZfXPkMI
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## DATE CBBTCUSD
## Length:1828 Min. : 211.2
## Class :character 1st Qu.: 737.6
## Mode :character Median : 4738.7
## Mean : 5035.9
## 3rd Qu.: 8256.0
## Max. :19650.0
data$date <- as.Date(data$DATE)
# Plot
data %>%
#tail(100) %>%
ggplot(aes(x=date, y=CBBTCUSD)) +
geom_line() +
geom_point() +
geom_smooth(method = lm)## `geom_smooth()` using formula 'y ~ x'
library(hrbrthemes)
#library(extrafont)
#font_import()
#loadfonts(device = "win")
data %>%
tail(10) %>%
ggplot( aes(x=date, y=CBBTCUSD)) +
geom_line( color="grey") +
geom_point(shape=21, color="black", fill="#69b3a2", size=6) +
theme_ipsum() +
ggtitle("Evolution of bitcoin price")data %>%
ggplot( aes(x=date, y=CBBTCUSD)) +
geom_line(color="#69b3a2") +
ylim(0,22000) +
annotate(geom="text", x=as.Date("2017-01-01"), y=20089,
label="Bitcoin price reached 20k $\nat the end of 2017") +
annotate(geom="point", x=as.Date("2017-12-17"), y=20089, size=10, shape=21, fill="transparent") +
geom_hline(yintercept=5000, color="orange", size=1) +
theme_ipsum()## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v tibble 3.1.0 v purrr 0.3.4
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
##
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
##
## group_rows
## Loading required package: viridisLite
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(patchwork)
library(viridis)
# Load dataset from github
dataETH <- read.csv("SMU Data/DV/CBETHUSD.csv")
dataLTC <- read.csv("SMU Data/DV/CBLTCUSD.csv")
dataBCH <- read.csv("SMU Data/DV/CBBCHUSD.csv")
dataBTC <- read.csv("SMU Data/DV/CBBTCUSD.csv")
dataETH$date <- as.Date(dataETH$DATE)
dataLTC$date <- as.Date(dataLTC$DATE)
dataBCH$date <- as.Date(dataBCH$DATE)
dataBTC$date <- as.Date(dataBTC$DATE)
dataETH['Coin'] = 'ETH'
dataLTC['Coin'] = 'LTC'
dataBCH['Coin'] = 'BCH'
dataBTC['Coin'] = 'BTC'
#change column name to value
names(dataETH)[2] <- "Value"
names(dataLTC)[2] <- "Value"
names(dataBCH)[2] <- "Value"
names(dataBTC)[2] <- "Value"
#by coin
allcoins <- rbind(dataETH, dataLTC, dataBCH, dataBTC)
a1 <- allcoins
#[order(as.Date(allcoins$DATE, format="%Y-%m-%d")),]
# Plot
a1 %>%
ggplot(aes(x=date, y=Value, group=Coin, color=Coin)) +
geom_area() +
scale_fill_viridis(discrete = TRUE) +
theme(legend.position="none") +
ggtitle("Crypto Trend") +
theme_ipsum() +
theme(
legend.position="none",
panel.spacing = unit(1, "lines"),
strip.text.x = element_text(size = 8),
plot.title = element_text(size=10)
) +
facet_wrap(~Coin) #Referencing from https://bookdown.org/content/b298e479-b1ab-49fa-b83d-a57c2b034d49/evolution.html