In this article, we will see how to create price volume heatmap of any stock ticker in R. The data used is historical intra-day ticks of the stock. A heatmap is a colored representation of data where individual values are represented as the shade of color.
The code is written in simple form so as easy to understand but multiple lines can be combined into one.
The code is written in simple form so as easy to understand but multiple lines can be combined into one.
Step 1
Get input data in format as attached in the zip. A sample row being ICICIBANK,20180409,09:08,277.75,277.75,277.75,277.75,86894 where "StockName","Date","Time","Open","HIgh","Low","Close","Volume" are meaning of the data.
Step 2
Install and Import Packages
Install and Import Packages
- install.packages("plyr")
- install.packages("lubridate")
- install.packages("ggplot2")
- install.packages("dplyr")
- library(plyr)
- library(lubridate)
- library(ggplot2)
- library(dplyr)
Step 3
To avoid seeing e+ in the volume legend.
To avoid seeing e+ in the volume legend.
- options(scipen=10000000)
Step 4
Set Variables and Import Data. The colors need to be identified correctly so that the heatmap make a good gradient.
Set Variables and Import Data. The colors need to be identified correctly so that the heatmap make a good gradient.
- tickerFile <- file.choose()
- APTicker <- read.csv(tickerFile,sep=",", fill=TRUE, stringsAsFactors=F, header = F)
- colnames(APTicker) <- c("StockName","Date","Time","Open","HIgh","Low","Close","Volume")
- # Colour shades for volume
- col1 = "#abefbf"
- col2 = "#22B14C"


Hadshana KamalanathanPosted Jul 22, 2018, 3:54 AM
Nice one...