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.
On Oct 4, 2012, at 4:49 PM, Guillaume2883 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 ? >Put a big zero on the axis?> > >-- David Winsemius, MD Alameda, CA, USA
On Oct 4, 2012, at 9:05 PM, David Winsemius wrote:> > On Oct 4, 2012, at 4:49 PM, Guillaume2883 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 ? >> > > Put a big zero on the axis?barchart(abs(-3:3) ~ letters[1:7], origin=0) require(grid) trellis.focus("panel", 1,1) grid.text(label=paste("0"), x = convertX(unit(4, "native"), "npc"), y = convertY(unit(0, "native"), "npc") ) trellis.unfocus() -- David Winsemius, MD Alameda, CA, USA
Thank for all your answer ! Here is another way I discoverd this morning : barplot(table(factor(variable, levels = 1:4)),names=c(1,2,3,4)) -- View this message in context: http://r.789695.n4.nabble.com/barplot-with-some-0-frequencies-tp4645102p4645208.html Sent from the R help mailing list archive at Nabble.com.
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