There are three approaches:
- Commands from packages such as
hist.data.frame()
- Quoting on variables or similar macrostructures
- Stacking variables and using faces
Packages
Other available commands:
library(plyr) library(psych) multi.hist(mpg) #error, not numeric multi.hist(mpg[,sapply(mpg, is.numeric)])
or maybe a multhist
from plotrix
, which I have not studied. Both of them do not offer the flexible form I was looking for.
Loops
As a beginner R, everyone advised me to stay away from the loops. So I did, but it might be worth a try here. Any suggestions are welcome. Perhaps you could comment on how to combine the charts into one file.
Stacking
My first suspicion was that stacking variables could get out of hand. However, this may be the best strategy for a reasonable set of variables.
In one example, I used the melt
function.
library(reshape2) mpgid <- mutate(mpg, id=as.numeric(rownames(mpg))) mpgstack <- melt(mpgid, id="id") pp <- qplot(value, data=mpgstack) + facet_wrap(~variable, scales="free") # pp + stat_bin(geom="text", aes(label=..count.., vjust=-1)) ggsave("mpg-histograms.pdf", pp, scale=2)
(As you can see, I tried putting value labels in columns for greater information density, but thatβs not so good. Labels on the x axis are also less ideal.)
No solution here is perfect, and there will be no one-size-fits-all team. But perhaps we can get closer to exploring a new dataset.