Richard Nguyen
2024-04-06
##
## 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
## Rows: 1048575 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (8): Timestamp, Open, High, Low, Close, Volume_(BTC), Volume_(Currency),...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
btc_data$PriceChange <- c(NA, diff(btc_data$Close))
# Remove NA values
btc_data1 <- btc_data[!is.infinite(btc_data$PriceChange) &
!is.na(btc_data$PriceChange), ]
# Calculate quantiles
quantiles <- quantile(btc_data1$PriceChange, probs = c(0.01, 0.99),
na.rm = TRUE)
# Plot histogram
ggplot(btc_data1, aes(x = PriceChange)) +
geom_histogram(binwidth = 1, fill = "#6D9EC1", color = "black") +
labs(title = "Histogram of Bitcoin Daily Price Changes",
x = "Daily Price Change",
y = "Frequency") +
xlim(quantiles[1], quantiles[2]) + # Apply
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))btc_plot <- ggplot(btc_data, aes(x = Date, y = Close)) +
geom_line(color = "#00BFC4") +
scale_y_log10() +
labs(title = "Price of Bitcoin Over Time",
x = "Date",
y = "Closing Price (USD)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
(axis.title.y = element_text(angle = 90, vjust = 0.5)))
print(btc_plot)