Visualize Cryptocurrency Market Caps using R

in cryptocurrencies •  6 years ago  (edited)

Create a treemap that visualizes the most current cryptocurrency market caps for the top 100 cryptocurrencies ranked according to current market cap using R software!

A treemap is a visual method for displaying hierarchical data that uses nested rectangles to represent the branches of a tree diagram. Each rectangle has an area proportional to the amount of data it represents.

Rplot.png

The treemap above was generated using R software and the script below. The script requires installation of the coinmarketcapr and treemap packages to run the code. Current market data is extracted by coinmarketcapr from the Coin Market Cap website service.

# Load libraries
library(coinmarketcapr)
library(treemap)
# Create data frames and get data
market_today <- get_marketcap_ticker_all()
df1 <- na.omit(market_today[,c('id','market_cap_usd')])
df1$market_cap_usd <- as.numeric(df1$market_cap_usd)
df1$formatted_market_cap <- paste0(df1$id,'\n','$',format(df1$market_cap_usd,big.mark = ',',scientific = F, trim = T))
# Create treemap
treemap(df1, index = 'formatted_market_cap', vSize = 'market_cap_usd', title = 'Cryptocurrency Market Cap', fontsize.labels=c(12, 8), palette='RdYlGn')

The above script also produces a data frame (table) of current market data (price_usd, price_btc, X24h_volume_usd, market_cap_usd, available_supply, total_supply, max_supply, percent_change_1h, percent_change_24h, percent_change_7d, last_updated) for the top 100 cryptocurrencies that can be analyzed using other R data mining functions.

References:

Coin Market Cap (2018). Website. https://coinmarketcap.com/

Tennekes, M (2017). treemap: Treemap Visualization. R package version 2.4.2. Vienna, Austria: R Foundation for Statistical Computing. https://CRAN.R-project.org/package=treemap

R Core Team (2018). R: A Language and Environment for Statistical Computing. Version 3.5.1. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/

Srivathsan, K (2017). coinmarketcapr: Get Cryptocurrencies Market Cap Prices from Coin Market Cap. R package version 0.1. Vienna, Austria: R Foundation for Statistical Computing. https://CRAN.R-project.org/package=coinmarketcapr

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!