[R] barplot with some 0 frequencies

Greg Snow 538280 at gmail.com
Fri Oct 5 21:31:20 CEST 2012


Others have shown barchart commands that include 0's.  My guess (which
could be wrong, feel free to ignore this e-mail if so) is that your
problem is due to the way you are creating/summarizing the data before
the plotting command is used.  R needs some way to know about what
bars you want, even if they are 0.  This is information that should be
a property of the data rather than a property of the graph (if made a
property of the data then the graph will take care of itself).

Compare the 2 plots created by the following code:

par(mfrow=c(2,1))
set.seed(1)
tmp <- sample( LETTERS[1:7], 10, TRUE )
barplot( table(tmp) )
tmp2 <- factor(tmp, levels=LETTERS[1:7])
barplot( table(tmp2) )

Does that show what your problem is? and what you would like the
results to look like?

The key is to create the data object (the factor 'tmp2' in this case)
which includes the information about the levels, even if they are not
present in this dataset.

On Thu, Oct 4, 2012 at 5:49 PM, Guillaume2883
<guillaume.bal.pro at gmail.com> wrote:
> Hi all,
>
> I am back with a new question !
> I recorded the occurence of 4 differents event on 20 places for a given time
> period.
> Now, I want to do some barplot of the frequency of theses events for each
> place, so it should be easy. My problem is that I want to see the
> frequencies of the 4 events on my barplots even if the frequency of some of
> them is 0.
> How could I do that ?
>
> Thanking you in advance for your help !
>
> Guillaume
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/barplot-with-some-0-frequencies-tp4645102.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.



-- 
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com




More information about the R-help mailing list