I've created histograms (using ggplot2) for price distributions of securities' data and I would like to display them side-by-side in one window for comparison. I've queried how to do this and have landed on par(mfrow=c(n,m)) but for whatever reason, when I call the histograms I have created, they each occupy an individual window (rather than a grid) and each consecutive call replaces the previous histogram. For example (see code below):
par(mfrow=c(3,3))
ggplot(data=BR_Pricing_F_M, aes(x=BR_Pricing_F_M$BR_Z7_F_M))+
geom_histogram(breaks=seq(BR_Z7_F_M_L-0.01, BR_Z7_F_M_H+0.01, by=0.01),
col="white",
fill="blue",
alpha= 1)+
labs(title="Z7 1 Month Price Distribution", x="Price Levels",
y="Frequency")
ggplot(data=BR_Pricing_F_Q, aes(x=BR_Pricing_F_Q$BR_Z7_F_Q))+
geom_histogram(breaks=seq(BR_Z7_F_Q_L-0.01, BR_Z7_F_Q_H+0.01, by=0.01),
col="white",
fill="red",
alpha= 1)+
labs(title="Z7 Last Quarter’s Price Distribution", x="Price Levels",
y="Frequency")
The above code yields two separate charts, when, according to the 3x3 matrix I specified with my par call, I should be able to populate a 3x3 grid with my ggplot2 generated histograms.
I've also tried assigning the plots to their own variable:
BR_Pricing_F_M_Hist <-ggplot(data=BR_Pricing_F_M, aes(x=BR_Pricing_F_M$BR_Z7_F_M))+
geom_histogram(breaks=seq(BR_Z7_F_M_L-0.01, BR_Z7_F_M_H+0.01, by=0.01),
col="white",
fill="blue",
alpha= 1)+
labs(title="Z7 1 Month Price Distribution", x="Price Levels",
y="Frequency")
BR_Pricing_Z7_F_Q_Hist <- ggplot(data=BR_Pricing_F_Q, aes(x=BR_Pricing_F_Q$BR_Z7_F_Q))+
geom_histogram(breaks=seq(BR_Z7_F_Q_L-0.01, BR_Z7_F_Q_H+0.01, by=0.01),
col="white",
fill="red",
alpha= 1)+
labs(title="Z7 Last Quarter’s Price Distribution", x="Price Levels",
y="Frequency")
par(mfrow=c(3,3))
BR_Pricing_F_M_Hist
BR_Pricing_F_Q_Hist
But the result is the same. Can anyone advise as to what I might be doing wrong?
Many thanks in advance!