[英]aggregate and plotting histograms with the same scale and axes
I have data named PACKS like this: 我有这样的名为PACKS的数据:
error CENTRE_B
-13 1104
-13 1303
-13 1303
2 1204
2 1403
2 1403
2 1403
2 1502
3 1503
My aim is to compare distributions. 我的目的是比较分布。 I want to to plot histograms for errors for each value of CENTRE_B.
我想绘制CENTRE_B每个值的误差直方图。 The problem is that the histograms have to be in the same scale.
问题在于直方图必须处于相同的比例。
I tried this: 我尝试了这个:
new.par <- par(mfrow=c(5, 5))
histograms = aggregate(error ~ CENTRE_B, PACKS, hist)
This plots histograms. 这将绘制直方图。 However, I don't know how to deliver additional argument to hist in aggregate (breaks = c(-80,80)).
但是,我不知道如何向hist传递额外的参数(breaks = c(-80,80))。
Another problem with this is that histograms seems to be data.table of dimension 2x45, so it does not contain histograms. 另一个问题是直方图似乎是2x45维的data.table,因此它不包含直方图。 So I don't know how to make changing parameters automatic.
因此,我不知道如何自动更改参数。
Thanks in advance for any suggestions. 在此先感谢您的任何建议。
Forget about aggregate
. 忘记
aggregate
。 Just use split
and do a simple for loop. 只需使用
split
并做一个简单的for循环即可。 Then you can input all args right into hist
. 然后,您可以将所有args直接输入
hist
。
new=split(PACKS$error,PACKS$CENTRE_B)
for(i in 1:length(new))
hist(new[[i]],main="Some fancy title", sub="don't forget you can use paste to change the title between loops")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.