I'm currently working with a rather large set of data, and have been tasked with generating histograms for multiple parts of the set. I have already worked out how to perform one aspect of the analysis using ggplolts:
Plot<-ggplot(melt(Data[1:200,1:4]),aes(x=value)) + geom_histogram() + facet_wrap(~variable)
This method has worked well for that first step of the process. However, now I've been tasked with taking the columns I was using and generating multiple histograms with different ranges of rows in each column. Is there an efficient way of doing this?
Update:
So lets say I have a dataframe with 1000 observations, across 4 columns.
Test<-rnorm(1000,3,.5)
Test<-as.data.frame(Test)
Test[,2]<-rnorm(1000,3,.5)
Test[,3]<-rnorm(1000,3,.5)
Test[,4]<-rnorm(1000,3,.5)
First I needed a way to select the same rows across ranges of columns, and create histograms for each one. The formula I found that worked wonders for this, was this:
PlotTest<-ggplot(melt(Test[1:100,1:4]),aes(x=value)) + geom_histogram() + facet_wrap(~variable)
PlotTest<-PlotTest+ggtitle("Results")+scale_x_continuous("Scores")+scale_y_continuous("Response Frequency", limits=c(0, 25))
PlotTest
https://i.stack.imgur.com/V13NV.png
The problem is now I would like to display graphs of multiple ranges within 1 column together. That is to say, I would ideally like to create a histogram for row ranges 1:299, 300:400, and 401:506 all from the same column and put them together on the same output in a similar style as I had previously. Is there any easy way of doing this process?Best Wishes, ~NaiveAnalyst
Update 2
A huge thanks goes out to the commenter that provided a solution to the aforementioned problem. The solution they found is reproduced below, seeing as their comment appears to have vanished.
install.packages("gridExtra")
library("gridExtra")
PlotTest1<-ggplot(melt(ManagersbyRegion[1:299,1]), aes(x=value))+ geom_histogram() +
ggtitle("Title")+scale_x_continuous("X-Values")+
scale_y_continuous("Y-Values")
PlotTest2<-ggplot(melt(ManagersbyRegion[300:400,1]), aes(x=value))+ geom_histogram() +
ggtitle("Title")+scale_x_continuous("X-Values")+
scale_y_continuous("Y-Values")
PlotTest3<-ggplot(melt(ManagersbyRegion[401:506,1]), aes(x=value))+ geom_histogram() +
ggtitle("Title")+scale_x_continuous("X-Values")+
scale_y_continuous("Y-Values")
grid.arrange(PlotTestI1, PlotTest2, PlotTest3)
Looking at the graphs, I noticed that the values would probably be better formatted as percentages. After digging for a good hour or so, I still am no closer to what I was looking for originally. Any advice on how to apply percentages to the y-axis would be exceedingly appreciated.
Best Wishes, ~Naive