Reputation: 561
I would like to plot all histogram in my data frame. One way I tried was hist.data.frame(df) which gave me very small pictures of each. Then I tried this code:
library(datasets)
data(iris)
X<-iris[,0:3]
par(mfrow=c(2,1))
histout=apply(X,2,hist)
This time, each picture is big enough but all of them have a title like Histogram NewX[,i]. When I have so many variables, this is very unclear. Is there anyway that I can add column name to each graph? Thank you!
Upvotes: 0
Views: 579
Reputation: 17715
I recommend you use lapply
and feed extra arguments to the hist
function in there (main
, xlab
, etc.). You could also use a loop.
For instance,
library(datasets)
data(iris)
X<-iris[,0:3]
par(mfrow=c(3,1))
lapply(names(X), function(k) hist(X[[k]], main=k))
Edit: Sorry, this is essentially the same answer as given in comments. I had not seen it.
Upvotes: 3