0

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

  • 3
    Can you add a reproducible [example of your data](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? – desc Sep 16 '16 at 22:26
  • can you also provide an example of your desired output? – Cyrus Mohammadian Sep 16 '16 at 22:52
  • Understood, I've tried to update the question to make it more informative. If you feel it needs and further clarification please let me know! :)! – NaiveAnalyst Sep 17 '16 at 22:07
  • It's not clear to me what you're looking for. By melting the data you have 4 different classes of data to plot but then you also want to have separate plots for each of the three row ranges. so to me its completely not clear what it is you're trying to facet_wrap... – Cyrus Mohammadian Sep 18 '16 at 01:58
  • an example of your desired output would go a long way...or a clearer explanation – Cyrus Mohammadian Sep 18 '16 at 01:59
  • Greetings Cyrus, The output I'm looking to generate can be found in the link toward the center of the page. I lack sufficient reputation to insert imbedded images at this time. The person that posted a beautiful code that worked wonders for what I originally needed has been reproduced above (I'm not sure why their comment disappeared), but I noticed when I applied it to my problem that using percentages on the y-axis may be more appropriate. Any suggestions people might have on that front would be appreciated. – NaiveAnalyst Sep 18 '16 at 03:44

0 Answers0