Merging histograms
Histograms help in studying the underlying distribution. It is more useful when we are trying to compare more than one histogram on the same plot; this provides us with greater insight into the skewness and the overall distribution.
In this recipe, we will study how to plot a histogram using the googleVis
package and how we merge more than one histogram on the same page. We will only merge two plots but we can merge more plots and try to adjust the width of each plot. This makes it easier to compare all the plots on the same page. The following plot shows two merged histograms:
How to do it…
In order to generate a histogram, we will install the googleVis
package as well as load the same in R:
install.packages("googleVis") library(googleVis)
We have downloaded the prices of two different stocks and have calculated their daily returns over the entire period. We can load the data in R using the read.csv()
function. Our main aim in this recipe is to plot two different histograms...