Re: [R] Histogram with colors according to factor

From: Hans W. Borchers <hwborchers_at_googlemail.com>
Date: Tue, 08 Jul 2008 05:23:27 -0700 (PDT)

No; thanks for your try, but this is not what I want.

Here each bar has one single color. I would like to render each bar with several colors according to the distribution of a factor.

I now learned that this is called "stacked histogram" (damned Excel). In the following entry

    https://stat.ethz.ch/pipermail/r-help/2007-April/129645.html

Deepayan Sarkar has provided a solution though he doubts its value. Still, I find "stacked histograms" a vuable tool during exploratory data analysis.

Hans Werner

Is this what you want?

dataset <- data.frame(x = c(rnorm(100), runif(100), rchisq(100, 1)), y = gl(3, 100, labels = LETTERS[1:3]))
ggplot(dataset, aes(x = x, fill = y)) + geom_histogram() ggplot(dataset, aes(x = x, fill = y)) + geom_histogram(position = "dodge")

HTH, Thierry




Hans W. Borchers
ABB Corporate Research Germany
-- 
View this message in context: http://www.nabble.com/Histogram-with-colors-according-to-factor-tp18336930p18337935.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.
Received on Tue 08 Jul 2008 - 12:29:56 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 08 Jul 2008 - 13:31:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive