My project is on the effect of social sentiment and social media on the crypto currency market. The graph I have included here is a comparison of the daily score of the Fear and greed index and the percent change in daily volume of bitcoin. The fear and greed index is a culmination of many factors with the main being Google trends, surveys, and social media sentiment. The volume change of bitcoin is the percentage change in the amount of bitcoin being moved around during a 24 hour period compared to the average.

# GRAPH 1
library(ggplot2)
library(data.table)
library(scales)

fear_greed <- fread('fear-greed.csv')
btc_data <- fread('BTC-USD (2014-2024).csv')

fear_greed[, Date := as.Date(Date, format='%Y-%m-%d')]
btc_data[, Date := as.Date(Date, format='%Y-%m-%d')]

fear_greed <- fear_greed[Date >= as.Date('2020-01-01') & Date <= as.Date('2022-12-31')]
btc_data <- btc_data[Date >= as.Date('2020-01-01') & Date <= as.Date('2022-12-31')]

btc_data[, Volume := as.numeric(Volume)]

merged_data <- merge(fear_greed, btc_data, by='Date', all.x=TRUE)

merged_data[, Volume_Change := c(NA, diff(Volume)) / shift(Volume, 1, type="lag") * 100]

fear_greed_plot <- data.frame(Date = merged_data$Date, Index = merged_data$Value)
volume_change_plot <- data.frame(Date = merged_data$Date, Volume_Change = merged_data$Volume_Change)

ggplot() +
  geom_line(data = fear_greed_plot, aes(x = Date, y = Index, colour = "Fear and Greed Index"), lwd=0.5) +
  geom_line(data = volume_change_plot, aes(x = Date, y = Volume_Change, colour = "Volume Change"), lwd=0.5, alpha=0.6) +
  scale_y_continuous(name = "Fear and Greed Index", 
                     sec.axis = sec_axis(~., name="Volume Change (%)")) +
  scale_colour_manual("", 
                      breaks = c("Fear and Greed Index", "Volume Change"),
                      values = c("Fear and Greed Index" = "red", "Volume Change" = "blue")) +
  labs(title = "Fear and Greed Index vs Bitcoin Volume Change (2020-2022)",
       x = "Date") +
  theme_minimal() +
  theme(legend.position = "bottom") +
  coord_cartesian(ylim = c(NA, 200)) # Enforces a maximum y value of 200
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_line()`).

#GRAPH 2

p1 <- ggplot(fear_greed_plot, aes(x = Date, y = Index)) +
      geom_line(colour = "black", lwd=0.5) +
      labs(title = "Fear and Greed Index (2020-2022)",
           x = "Date",
           y = "Index") +
      theme_minimal()

p2 <- ggplot(volume_change_plot, aes(x = Date, y = Volume_Change)) +
      geom_line(colour = "blue", lwd=0.5) +
      labs(title = "Bitcoin Volume Change (%) (2020-2022)",
           x = "Date",
           y = "Volume Change (%)") +
      theme_minimal()

gridExtra::grid.arrange(p1, p2, ncol=1)
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_line()`).

The major differences between graph 2 and graph 1 is that graph 2 is split into two and has a different color pallet. The graphs being split apart allow the reader to better view both trends and it is still easy to see the correlation between the two variables. The change of color from red to black is also necessary as the use of red beforehand could confuse the reader as when viewing graphs related to finance red is generally viewed in a negative connotation.

#GRAPH 3
library(zoo)
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:data.table':
## 
##     yearmon, yearqtr
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(gridExtra)

merged_data[, Index := rollapply(Value, 7, mean, fill = NA, align = 'right')]
merged_data[, Percent_Volume_Change := rollapply(Volume_Change, 7, mean, fill = NA, align = 'right')]

fear_greed_data <- merged_data[, .(Date, Index)]
volume_change_data <- merged_data[, .(Date, Percent_Volume_Change)]

p1 <- ggplot(fear_greed_data, aes(x = Date, y = Index)) +
  geom_line(colour = "black", size=0.5) +
  labs(title = NULL, y = "Fear and Greed Index") +
  theme_minimal() +
  theme(legend.position = "none", axis.title.x = element_blank())
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
p2 <- ggplot(volume_change_data, aes(x = Date, y = Percent_Volume_Change)) +
  geom_line(colour = "blue", size=0.5) +
  labs(title = "Bitcoin Volume %Change (2020-2022)", y = "Volume Change (%)") +
  theme_minimal() +
  theme(legend.position = "none") +
  ylim(-20, 30)


combined_plot <- grid.arrange(p1, p2, nrow=2)
## Warning: Removed 6 rows containing missing values or values outside the scale range
## (`geom_line()`).
## Warning: Removed 7 rows containing missing values or values outside the scale range
## (`geom_line()`).

print(combined_plot)
## TableGrob (2 x 1) "arrange": 2 grobs
##   z     cells    name           grob
## 1 1 (1-1,1-1) arrange gtable[layout]
## 2 2 (2-2,1-1) arrange gtable[layout]

The main changes made between graph 2 and 3 are the addition of line smoothing and the alteration of the y axis. The use of line smoothing allows the reader to better see overall trends and see the bigger picture. The alteration of the y axis is also a necessary change as it allows the reader to better see the movement of volume.

#GRAPH 4
library(plotly)
## 
## 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
p1 <- ggplot(fear_greed_data, aes(x = Date, y = Index)) +
  geom_line(colour = "black", size=0.5) +
  labs(title = NULL, y = "Fear and Greed Index") + # Remove title here
  theme_minimal() +
  theme(legend.position = "none", axis.title.x = element_blank()) # Remove x-axis title

p2 <- ggplot(volume_change_data, aes(x = Date, y = Percent_Volume_Change)) +
  geom_line(colour = "blue", size=0.5) +
  labs(title = "Bitcoin Volume %Change (blue), Fear-Greed index score(black) (2020-2022)", y = "Volume Change (%)") + 
  theme_minimal() +
  theme(legend.position = "none") +
  ylim(-20, 30) 

p1_interactive <- ggplotly(p1, tooltip = c("x", "y"))
p2_interactive <- ggplotly(p2, tooltip = c("x", "y"))

combined_plot <- subplot(p1_interactive, p2_interactive, nrows = 2, heights = c(0.5, 0.5), margin = 0.05)

combined_plot

Graph 4’s biggest change is the introduction of an interactive element through plotly. The interactive element allows the reader to be able to go between graphs and compare exact days to each other, giving them a better understanding of the relationship.

p1 <- ggplot(fear_greed_data, aes(x = Date, y = Index)) +
  geom_line(colour = "black", size=0.25) +  # Thinner line by setting size to 0.25
  labs(title = NULL, y = "Fear and Greed Index") +
  theme_minimal() +
  theme(legend.position = "none", axis.title.x = element_blank())

p2 <- ggplot(volume_change_data, aes(x = Date, y = Percent_Volume_Change)) +
  geom_line(colour = "blue", size=0.25) +  # Thinner line by setting size to 0.25
  labs(title = "Bitcoin Volume %Change (blue), Fear-Greed index score(black) (2020-2022)", y = "Volume Change (%)") + 
  theme_minimal() +
  theme(legend.position = "none") +
  ylim(-20, 30) 

p1_interactive <- ggplotly(p1, tooltip = c("x", "y"))
p2_interactive <- ggplotly(p2, tooltip = c("x", "y"))

combined_plot <- subplot(p1_interactive, p2_interactive, nrows = 2, heights = c(0.5, 0.5), margin = 0.05)

combined_plot

Graph 5’s alteration is the changing of the line width to make the lines appear thinner. The motive behind this is to allow the viewer to see trends in the data better by having less overlap and more differentiation between each day. This is the best plot when compared to the visualizations before it as it continually improves on the designs before it.