I need to create different histograms from a dataframe. Currently I am using this loop to generate individual histograms
An example:
df<-matrix(NA,2000,5) df[,1]<-rnorm(2000,1,1) df[,2]<-rnorm(2000,2,1) df[,3]<-rnorm(2000,3,1) df[,4]<-rnorm(2000,4,1) df[,5]<-rnorm(2000,5,1) df<-data.frame(df) colnames(df) <- c("HB1", "HB2", "HB3","HB4", 'HB5') Loop:
out<-list() for (i in 1:5){ x = df[,i] out[[i]] <- ggplot(data.frame(x), aes(x)) + geom_histogram(aes(y=..count../sum(..count..)), fill="red", lwd=0.9, breaks=seq(0,5,0.1), col=("black"), alpha=I(.9)) + labs(x=expression(d["HB"]), y="Frequency") grid.arrange(out[[i]], ncol=1) } The output are 5 figures like this one:
But now I would like to do a comparison overlapping all of them. This figure is what I really want:
Thanks in advance

