[R] Plot grouped histograms

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Fri Oct 10 16:23:26 CEST 2008

Another solution would be

faclevels<-c("Not","Little","Somewhat","Very", NA)
group <- factor(1:6)
svdf<-data.frame(value = sample(group, 400, TRUE), category =
ggplot(svdf, aes(x = value, fill = category)) + geom_histogram(position
= "dodge")



ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be 

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org]
Namens Jim Lemon
Verzonden: vrijdag 10 oktober 2008 14:26
Aan: soeren.vogel op eawag.ch
CC: r-help op r-project.org
Onderwerp: Re: [R] Plot grouped histograms

soeren.vogel op eawag.ch wrote:
> r11 -- r16 are variables showing a reason for usage of a product in 6 
> different situations. Each variable is a factor with 4 levels imported

> from a SPSS sav file with labels ranging from "not important" to "very

> important", and NA's for a sample of N = 276.
> (1) I need a chi square test of independence showing that the reason 
> does not differ depending on the situation.
> (2) I need a single coloured histogram plot. The x axis should be 
> grouped by the 6 situation with small space between the groups, each 
> group should show different bars for each factor value ("not 
> important", "little...", ..., "NA's"), but NA's is not necessary.
> I've been googling the whole day, searching the mailing list and 
> handbooks, and struggled through the somewhat R programmer specific 
> documentation. Beeing a newby in R, I'm now afraid that I have to go 
> back to SPSS and Excel where my tasks would be a work of an hour. But 
> I was told "euphoric" that R may solve many of the problems I have 
> (and don't like) with SPSS, or having to separate calculation (SPSS, 
> Excel by hand) and plotting (GNUplot).
> So my two questions are: How can I easily solve my 2 tasks? Secondly, 
> is R really recommended for R newbys in daily work?

Hi Soeren,
For number 1:

chisq.test(svfreqs) #see below

but I don't think that this is the best way to test this.
For number 2:

barp(svfreqs,main="Frequencies of importance ratings",ylim=c(0,100),


R-help op r-project.org mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.

More information about the R-help mailing list