Load in Libraries

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.0.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.0.3
## 
## 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
library(scales)
library(ggthemes)
## Warning: package 'ggthemes' was built under R version 4.0.3

Setting the working directory and loading in the data

setwd("/Users/Joeyc/Documents/School/Fall 2021/Data 110/DataSets/")
getwd()
## [1] "C:/Users/Joeyc/Documents/School/Fall 2021/Data 110/DataSets"
CC = read.csv("CryptoCurrencies.csv")

Change the Dates to the correct format

CC$Date <- as.Date(CC$Date, format = "%m/%d/%Y")
typeof(CC$Date)
## [1] "double"
class(CC$Date)
## [1] "Date"

Changing variables from characters to numeric

CC$Close <- as.numeric(CC$Close)
## Warning: NAs introduced by coercion
CC$Open <- as.numeric(CC$Open)
## Warning: NAs introduced by coercion
CC$High <- as.numeric(CC$High)
## Warning: NAs introduced by coercion
CC$Low <- as.numeric(CC$Low)
## Warning: NAs introduced by coercion
CC$Adj.Close <- as.numeric(CC$Adj.Close)
## Warning: NAs introduced by coercion
CC$Volume <- as.numeric(CC$Volume)
## Warning: NAs introduced by coercion

Renaming column where name was messed up

CC$Currency <- CC$ï..Currency

Now let’s view the data to make sure everything looks good

View(CC)

Creating the first graphic: This graphic is just the overall price change in a line graph of the top 5 cryptocurrencies according to market cap. As you can tell by the graphic, with BTC being so expensive it takes away from all the other currencies. Therefore, it is tough to get a sense of any of the other ones.

CC_Graph <- ggplot(data = CC, aes(x= Date, y= Close, color = Currency))+
  geom_line()+
  scale_x_date(date_labels = "%Y")+
  scale_y_continuous(labels=scales::dollar_format())+
  theme_clean()+
  ylab("Price")+
  xlab("Year")+
  ggtitle("Cryptocurrencies Price Change from 2015 to 2021")

CC_Graph

### I was curious how these cryptocurrencies produced before the year 2017. I chose 2017 because BTC has it’s first bubble in 2018 so I wanted to know how it performed before this $20k bubble. I chose a facet wrap to get a sense of the other currencies around this time as well. To see if they even played a role. As you can see ADA and BNB were not even created by 2017. While XRP was in it’s infancy at under 1 cent.

CC2015 <- CC %>%
  filter(Date < '2017-01-01')
CC2_Graph <- ggplot(data = CC2015, aes(x= Date, y= Close, color = Currency))+
  geom_line()+
  facet_wrap(~Currency, scales = "free")+
  scale_x_date(date_labels = "%m-%Y")+
  scale_y_continuous(labels=scales::dollar_format())+
  theme_clean()+
  ylab("Price")+
  xlab("Date")+
  ggtitle("Cryptocurrencies Price Change from 2015 to 2017")

CC2_Graph

In this next graphic I just wanted to see how each of these currencies performed during 2021 to get a sense of how the market is currently performing. For this I made a basic facet wrap.

CC3_Graph <- ggplot(data = CC, aes(x= Date, y= Close))+
  geom_line()+
  facet_wrap(~Currency, scales = "free")+
  scale_x_date(date_labels = "%m", limits = c(as.Date("2021-1-01"), as.Date("2021-10-01")))+
  scale_y_continuous(labels=scales::dollar_format())+
  ylab("Price")+
  xlab("Date")+
  ggtitle("Cryptocurrencies Price Change in 2021")

CC3_Graph
## Warning: Removed 1937 row(s) containing missing values (geom_path).

This facet wrap gives us a better view of how the top 5 market cap cryptocurrencies correlate this year. Using the free scale on these you can tell they spike and similar times and fall at similar times. Even though their spikes and falls are not the same % spikes you can see they spiked around April or May and then fell right after this spike.

Next I wanted to make a graphic without BTC to see if I could get a better sense of the data.

CC1 <- filter(CC, Currency!='BTC')
CC4_Graph <- ggplot(data = CC1, aes(x= Date, y= Close, color = Currency))+
  geom_line()+
  scale_x_date(date_labels = "%Y")+
  scale_y_continuous(labels=scales::dollar_format())+
  theme_clean()+
  ylab("Price")+
  xlab("Year")+
  ggtitle("Cryptocurrencies Price Change from 2015 to 2021")

CC4_Graph

Now let’s filter out ETH, since only filtering out BTC didn’t do much.

CC2 <- filter(CC1, Currency!='ETH')
CC5_Graph <- ggplot(data = CC2, aes(x= Date, y= Close, color = Currency))+
  geom_line()+
  scale_x_date(date_labels = "%Y")+
  scale_y_continuous(labels=scales::dollar_format())+
  theme_clean()+
  ylab("Price")+
  xlab("Year")+
  ggtitle("Cryptocurrencies Price Change from 2015 to 2021")

CC5_Graph

Finally, filtering out BNB to show two currencies with similar price points. As you can see with all these points towards the end we see this up and down then back up trend. Let’s get a closer look after this graphic.

CC3 <- filter(CC2, Currency!='BNB')
CC6_Graph <- ggplot(data = CC3, aes(x= Date, y= Close, color = Currency))+
  geom_line()+
  scale_x_date(date_labels = "%Y")+
  scale_y_continuous(labels=scales::dollar_format())+
  theme_clean()+
  ylab("Price")+
  xlab("Year")+
  ggtitle("ADA and XRP Price Change from 2015 to 2021")

CC6_Graph

While this is not 100% accurate, I am going to mutate the currencies to get these dollar value to similar numbers so it is easier to compare the figures on one graph. This is an alternative to the facet wrap I showed earlier.

CCBTC2021 <- CC%>%
  filter(Date > '2021-01-01')%>%
  filter(Currency == 'BTC') %>%
  mutate(Close = Close/20000)
CCADA2021 <- CC%>%
  filter(Date > '2021-01-01')%>%
  filter(Currency == 'ADA')
CCXRP2021 <- CC%>%
  filter(Date > '2021-01-01')%>%
  filter(Currency == 'XRP')
CCETH2021 <- CC%>%
  filter(Date > '2021-01-01')%>%
  filter(Currency == 'ETH') %>%
  mutate(Close = Close/1000)
CCBNB2021 <- CC%>%
  filter(Date > '2021-01-01')%>%
  filter(Currency == 'BNB') %>%
  mutate(Close = Close/200)
CC8_Graph <- ggplot(NULL, aes(x= Date, y= Close, col = Currency))+
  geom_line(data = CCBTC2021, size=1)+
  geom_line(data = CCADA2021, size=1)+
  geom_line(data = CCXRP2021, size=1)+
  geom_line(data = CCETH2021, size=1)+
  geom_line(data = CCBNB2021, size=1)+
  scale_x_date(date_labels = "%m-%Y")+
  scale_y_continuous(labels=scales::dollar_format())+
  theme_clean()+
  ylab("Scaled Price")+
  xlab("Date")+
  ggtitle("Scaled Price Change in 2021")

CC8_Graph

The source and topic of the data, any variables included, what kind of variables they are, how you cleaned the dataset up (be detailed and specific, using proper terminology where appropriate).

I downloaded this data from Kaggle. The data represents the price of different crypto currencies from 2015 to 2021. The variables included, the name of each cryptocurrency, the date, the prices at closing, opening, their highs and lows and the volume traded. I cleaned the dataset in a couple of different ways. The date format used in the csv file was m/d/y. While that looks nice, R prefers Y-M-D so I used the as.Date function to change it around. I had to specify what format the csv originally had in order to do this (CC\(Date <-as.Date(CC\)Date, format = “%m/%d/%Y”)). Since R thought that the numbers in the csv were characters, I also had to use the as.numeric function to change the numbers from characters to numerics in R so I could plot them. Another issue was that R transferred one column’s name incorrectly so I had to manually correct it in R CC\(Currency <- CC\)ï..Currency.

What the visualization represents, any interesting patterns or surprises that arise within the visualization.

I created multiple visualizations in the process of making my final visualization. My final visualization represented the scaled price change of the top 5 highest market cap cryptocurrencies in the world. I achieved this by using the dplyr functions filter and mutate to filter the year I wanted and the currency I wanted and mutate helped me scale the currencies. I was surprised at first to see that they had similar rise and runs at similar points in time this year because the first graph showed BTC dominating the market followed by Ethereum. Once I used the facet wrap with free scales, I saw the trend so I had to figure out how to get them all on one graphic.

Anything that you might have shown that you could not get to work or that you wished you could have included.

####Something I wanted to show but could not figure out is the % change during 2021 instead of just scaling it myself. I feel like my data is not 100% accurate but it was as close as I could get to showing what I wanted to show.