[R] How to compare stacked histograms/datasets
Joshua Wiley
jwiley.psych at gmail.com
Sat Jul 7 22:30:53 CEST 2012
Hi,
Probably easier to work with the raw data, but whatever. If your data
is in a data frame, dat,
## create row index
dat$x <- 1:21
## load packages
require(ggplot2)
require(reshape2)
## melt the data frame to be long, long dat, ldat for short
ldat <- melt(dat, id.vars="x")
## plot the distributions
ggplot(ldat, aes(x, value, colour = variable)) + geom_line()
## they don't really look on the same scale
## we could scale the data first to have equal mean and variance
dat2 <- as.data.frame(scale(dat))
## remake index so it is not scaled
dat2$x <- 1:21
ldat2 <- melt(dat2, id.vars="x")
ggplot(ldat2, aes(x, value, colour = variable)) + geom_line()
which yields the attached PDF (maybe scrubbed on the official list as
most file extensions are, but should go through to you personally via
gmail). I'm not sure it's the greatest approach ever, but it gives
you a sense if they go up and down together or at different points.
Cheers,
Josh
On Fri, Jul 6, 2012 at 1:55 PM, Atulkakrana <atulkakrana at gmail.com> wrote:
> Hello All,
>
> I have a couple of stacked histograms which I need to compare/evaluate for
> similarity or difference.
> http://r.789695.n4.nabble.com/file/n4635668/Selection_011.png
>
> I believe rather than evaluating histograms is will be east to work with
> dataset used to plot these stacked histograms, which is in format:
>
> RED PURPLE BLUE
> GREY YELLOW
> 22.0640569395 16.9483985765 0 60.987544484 0
> 8.1850533808 8.8523131673 0 82.962633452 0
> 6.8505338078 6.8950177936 0.756227758 85.4982206406 0.5338078292
> 6.7615658363 5.2491103203 1.6459074733 86.3434163701 0.6672597865
> 5.8274021352 7.384341637 2.1352313167 84.653024911 1.1565836299
> 7.8736654804 6.628113879 1.5569395018 83.9412811388 1.2010676157
> 7.1619217082 8.1850533808 1.2455516014 83.4074733096 1.3790035587
> 5.5604982206 10.2758007117 1.0676156584 83.0960854093 1.0231316726
> 7.1174377224 7.6067615658 0.7117437722 84.5640569395 0.756227758
> 7.8736654804 3.9590747331 0.6672597865 87.5 0.3113879004
> 7.6512455516 7.8736654804 0.5338078292 83.9412811388 0.5338078292
> 7.6067615658 8.9857651246 1.4679715302 81.9395017794 0.3558718861
> 8.9412811388 8.0071174377 1.3790035587 81.6725978648 0.5782918149
> 19.0836298932 9.2081850534 2.1352313167 69.5729537367 1.3790035587
> 14.9911032028 11.0765124555 3.2028469751 70.7295373665 1.0676156584
> 15.3914590747 10.8985765125 3.024911032 70.6850533808 1.2900355872
> 17.4822064057 12.5444839858 2.4911032028 67.4822064057 1.334519573
> 15.8362989324 13.0338078292 2.0017793594 69.128113879 1.334519573
> 17.037366548 10.4537366548 2.4021352313 70.1067615658 1.2010676157
> 20.2846975089 10.0088967972 0 69.706405694 1.0676156584
> 28.7366548043 12.6334519573 0 58.6298932384 0
>
> Is there any possible way I can compare such dataset from multiple
> experiments (n=8) and visually show (plot) that these datasets are in
> consensus or differ from each other?
>
> Awaiting reply,
>
> Atul
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-compare-stacked-histograms-datasets-tp4635668.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plots.pdf
Type: application/pdf
Size: 7111 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120707/888d3a0e/attachment.pdf>
More information about the R-help
mailing list