[R] visualizing frequencies

Duncan Murdoch murdoch at stats.uwo.ca
Sun Jun 26 15:23:56 CEST 2005


Mag. Ferri Leberl wrote:
> Dear everybody,
> 
> In our game-theory lesson we have run several classroom-experiments where the 
> students had to decide for a natural number between one and seven. I have 
> troubles now to visualize the results: be a the vector of answers.
> 
> hist(a) will not assume natural numbers as answers, but rational. It will make 
> the brakes exactly at the natural numbers,  which is difficult to interpret, 
> as only natural numbers may be employed.

Read ?hist.  The "breaks" argument allows you to control where the 
breaks occur.  I'd guess you'd want hist(a, breaks = 0:7 + 0.5).
> 
> barplot(a) or barplot(a,1:7) will not aggregate the answers. If three students 
> returned the number seven, it will show three bars to the size of seven 
> instead one bar to the size of three on index seven.
> 
> barplot(1:7,a), in this case, will show the bar at index seven, wut it will be 
> to the hight of seven and to the width of three.
> 
> I also wanted to show the results of the different versions of the experiment 
> in ONE plot. As the number of participants varied I googled around in the 
> R-Archives and got to recognize plot.edf. As a pitty, this function seems to 
> set the index the wrong way round: the function starts with the number of 
> students deciding for seven, but indexes them with one.

There are many different ways to do this.  You can have multiple panels 
in one plot with par(mfrow=...) or using the lattice package, you can 
overlap multiple histograms in one plot with "add=T" in the call to 
hist() (but the results don't look very good), you can construct 
multiple side-by-side histograms using barplot, etc.

You should decide exactly what you want the plot to look like, then if 
you can't figure out how to draw it after reading the docs, ask here.

Duncan Murdoch

P.S. Your email address ferri.leberl at gmx.at fails with a "mailbox 
disabled" message.




More information about the R-help mailing list