我已经为证券数据的价格分布创建了直方图(使用ggplot2),我想将它们并排显示在一个窗口中进行比较。我已经查询了如何做到这一点并且已经降低了标准杆(mfrow = c(n,m))但是无论出于何种原因,当我调用我创建的直方图时,它们各自占据一个单独的窗口(而不是网格)并且每个连续调用替换先前的直方图。例如(见下面的代码):
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")
上面的代码产生两个单独的图表,根据我用par调用指定的3x3矩阵,我应该能够用我的ggplot2生成的直方图填充3x3网格。
我也尝试将这些图分配给他们自己的变量:
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
但结果是一样的。谁能告诉我可能做错了什么?
非常感谢提前!