I have data named PACKS like this:
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. 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)).
Another problem with this is that histograms seems to be data.table of dimension 2x45, so it does not contain histograms. So I don't know how to make changing parameters automatic.
Thanks in advance for any suggestions.
Forget about aggregate
. Just use split
and do a simple for loop. Then you can input all args right into 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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.