Analysing Cryptocurrency Market in R

October 26, 2017
By

(This article was first published on R Programming – DataScience+, and kindly contributed to R-bloggers)

Cryptocurrency market has been growing rapidly that being an Analyst, It intrigued me what does it comprise of. In this post, I’ll explain how can we analyse the Cryptocurrency Market in R with the help of the package coinmarketcapr. Coinmarketcapr package is an R wrapper around coinmarketcap API.

To get started, Let us load the library into our R session and Plot the top 5 Cryptocurrencies.

library(coinmarketcapr)
plot_top_5_currencies()

Gives this plot:

The above plot clearly shows how bitcoin is leading the market but that does not give us the picture of how the marketshare is split among various cryptocurrencies, so let us get the complete data of various cryptocurrencies.

market_today <- get_marketcap_ticker_all()
head(market_today[,1:8])
              id         name symbol rank price_usd  price_btc X24h_volume_usd market_cap_usd
1      bitcoin      Bitcoin    BTC    1   5568.99        1.0    2040540000.0  92700221345.0
2     ethereum     Ethereum    ETH    2   297.408  0.0537022     372802000.0  28347433482.0
3       ripple       Ripple    XRP    3  0.204698 0.00003696     100183000.0   7887328954.0
4 bitcoin-cash Bitcoin Cash    BCH    4   329.862  0.0595624     156369000.0   5512868154.0
5     litecoin     Litecoin    LTC    5    55.431   0.010009     124636000.0   2967255097.0
6         dash         Dash   DASH    6   287.488  0.0519109      46342600.0   2197137527.0

Having extracted the complete data of various cryptocurrencies, let us try to visualize the marketshare split with a treemap. For plotting, let us extract only the two columns ID and market_cap_usd and convert the market_cap_usd into numeric type and a little bit of number formatting for the treemap labels.

library(treemap)
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))
treemap(df1, index = 'formatted_market_cap', vSize = 'market_cap_usd', title = 'Cryptocurrency Market Cap', fontsize.labels=c(12, 8), palette='RdYlGn')

Gives this plot:

The above visualization explains the whole cryptocurrency market is propped by two currencies primarily – Bitcoin and Etherum and even the second ranked Etherum is far behind than Bitcoin which is the driving factor of this market. But it is also fascinating (and shocking at the same time) that both Bitcoin and Etherum together create a 100 Billion Dollar (USD) market. Whether this is a sign of bubble or no – We’ll leave that for market analysts to speculate, but being a data scientist or analyst, We have a lot of insights to extract from the above data and it should be interesting analysing such an expensive market.

    Related Post

    1. Time Series Analysis in R Part 3: Getting Data from Quandl
    2. Pulling Data Out of Census Spreadsheets Using R
    3. Extracting Tables from PDFs in R using the Tabulizer Package
    4. Extract Twitter Data Automatically using Scheduler R package
    5. An Introduction to Time Series with JSON Data

    To leave a comment for the author, please follow the link and comment on their blog: R Programming – DataScience+.

    R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



    If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

    Comments are closed.

    Search R-bloggers

    Sponsors

    Never miss an update!
    Subscribe to R-bloggers to receive
    e-mails with the latest R posts.
    (You will not see this message again.)

    Click here to close (This popup will not appear again)