Re: [R] how to include bar values in a barplot?
Donatas G. wrote: > On Tuesday 07 August 2007 22:09:52 Donatas G. wrote: >> How do I include bar values in a barplot (or other R graphics, where this >> could be applicable)? >> >> To make sure I am clear I am attaching a barplot created with >> OpenOffice.org which has barplot values written on top of each barplot. > > Here is the barplot mentioned above: > http://dg.lapas.info/wp-content/barplot-with-values.jpg > > it appeaars that this list does not allow attachments... > That is a TERRIBLE graphic. Can't we finally leave this subject alone? Frank Harrell __ R-help@stat.math.ethz.ch 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.
Re: [R] how to include bar values in a barplot?
Welcome to the world of R. I'm glad that you found the discussion enlightening, now that you have thought about things a bit, here is some code to try out that shows some of the alternatives to the original plots you provided (which is best depends on your audience and what your main question of interest is (which comparisons are most important): tmp <- c(34,22,77) tmp2 <- barplot(tmp, names=LETTERS[1:3]) # put numbers at bottom of bars axis(1, at=tmp2, labels=as.character(tmp), tick=FALSE, line = -1) # put numbers at top of plot axis(3, at=tmp2, labels=as.character(tmp), tick=FALSE) # horizontal boxplot op <- par(mar=c(5,6,4,6)+0.1) tmp2 <- barplot(tmp, names=LETTERS[1:3], horiz=TRUE) # put numbers on the right axis(4, at=tmp2, labels=as.character(tmp), tick=FALSE, las=1) par(op) # the dotplot library(Hmisc) dotchart2(tmp, labels=LETTERS[1:3], auxdata=tmp, xlim=range(0,tmp)) # alternatives to stacked bars tmp1 <- c(8, 22, 60, 10, 10, 21, 59, 10) tmp2 <- factor(rep(c('A','B'), each=4)) tmp3 <- factor(rep(1:4, 2)) dotchart2(tmp1, groups=tmp2, labels=tmp3, xlim=range(0,tmp1)) dotchart2(tmp1, groups=tmp3, labels=tmp2, xlim=range(0,tmp1)) library(lattice) tmp <- data.frame( tmp1=tmp1, tmp2=tmp2, tmp3=tmp3 ) dotplot( tmp2~tmp1, data=tmp, groups=tmp3, pch=levels(tmp3), scales=list(x=list(limits=range(0,tmp1))) ) dotplot( tmp3~tmp1, data=tmp, groups=tmp2, pch=levels(tmp2), xlim=range(0,tmp1) ) -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Donatas G. > Sent: Friday, August 10, 2007 2:15 AM > To: r-help@stat.math.ethz.ch > Subject: Re: [R] how to include bar values in a barplot? > > Quoting Greg Snow <[EMAIL PROTECTED]>: > > > My original intent was to get the original posters out of > the mode of > > thinking they want to match what the spreadsheet does and into > > thinking about what message they are trying to get across. To get > > them (and possibly others) thinking I made the statements a > bit more > > bold than my actual position (I did include a couple of qualifiers). > > As an original poster (and a brand new user of R), I would > like to comment on the educational experience I have just received. ;) > > The discussion was interesting and enlightening, and gives > some good ideas about the ways (tables, graphs, graphs with > numbers etc.) to get the data accross to the ones one is > presenting to. I see some of you guys do feel quite strongly > about it, which is fine for me. I do not. I usually care for > barplot aesthetics and informativeness more than for visual > simplicity. That may change in time :) > > I see R graphical capabilities are huge but hard to access at > times - that is when spreadsheet seems preferrable. For > example, as a user of Linux I still cannot figure out why the > fonts (and graphics in general) look much more ugly on R in > Linux than they do in R on Windows - no smoothing, sub-pixell > hinting, anything like that. That is what my next free time > homework on R will be about > :) > > Sincerely > > Donatas Glodenis > PhD candidate > Department of Sociology of the Faculty of Philosophy Vilnius > University Lithuania > > __ > R-help@stat.math.ethz.ch 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. > __ R-help@stat.math.ethz.ch 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.
Re: [R] how to include bar values in a barplot?
Quoting Greg Snow <[EMAIL PROTECTED]>: > My original intent was to get the original posters out of the mode of > thinking they want to match what the spreadsheet does and into thinking > about what message they are trying to get across. To get them (and > possibly others) thinking I made the statements a bit more bold than my > actual position (I did include a couple of qualifiers). As an original poster (and a brand new user of R), I would like to comment on the educational experience I have just received. ;) The discussion was interesting and enlightening, and gives some good ideas about the ways (tables, graphs, graphs with numbers etc.) to get the data accross to the ones one is presenting to. I see some of you guys do feel quite strongly about it, which is fine for me. I do not. I usually care for barplot aesthetics and informativeness more than for visual simplicity. That may change in time :) I see R graphical capabilities are huge but hard to access at times - that is when spreadsheet seems preferrable. For example, as a user of Linux I still cannot figure out why the fonts (and graphics in general) look much more ugly on R in Linux than they do in R on Windows - no smoothing, sub-pixell hinting, anything like that. That is what my next free time homework on R will be about :) Sincerely Donatas Glodenis PhD candidate Department of Sociology of the Faculty of Philosophy Vilnius University Lithuania __ R-help@stat.math.ethz.ch 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.
Re: [R] how to include bar values in a barplot?
Do you mean like this? my.values=10:15 x <- barplot(my.values, ylim=c(0,11)) text(x, my.values, labels=my.values, pos=3) It is very bad practice and OOo should have its fingers slapped for perpetuating such a form. --- "Donatas G." <[EMAIL PROTECTED]> wrote: > How do I include bar values in a barplot (or other R > graphics, where this > could be applicable)? > > To make sure I am clear I am attaching a barplot > created with OpenOffice.org > which has barplot values written on top of each > barplot. > > -- > Donatas Glodenis > http://dg.lapas.info > > __ > R-help@stat.math.ethz.ch 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. > __ R-help@stat.math.ethz.ch 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.
Re: [R] how to include bar values in a barplot?
Please see ?format ?round Note that text() is said to expect a character vector, so why did you supply a numeric vector? labels: a character vector or expression specifying the _text_ to be written. An attempt is made to coerce other language objects (names and calls) to expressions, and vectors and other classed objects to character vectors by 'as.character'. If 'labels' is longer than 'x' and 'y', the coordinates are recycled to the length of 'labels'. and try as.character(vals) for yourself. > Is there any way to round up those numbers? See library(fortunes); fortune("Yoda") On Wed, 8 Aug 2007, Donatas G. wrote: > On Wednesday 08 August 2007 00:40:56 Donatas G. wrote: >> On Tuesday 07 August 2007 22:09:52 Donatas G. wrote: >>> How do I include bar values in a barplot (or other R graphics, where this >>> could be applicable)? >>> >>> To make sure I am clear I am attaching a barplot created with >>> OpenOffice.org which has barplot values written on top of each barplot. >> >> After more than two hours search I finally found a solution: >> http://tolstoy.newcastle.edu.au/R/help/06/05/27286.html > > Hey, the solution happens to be only partiall... If the values are not real > numbers, and have a lot of digits after the dot, the graph might become > unreadable... > > see this > > vals <- > c(1,1.1236886,4.77554676,5.3345245,1,1.1236886,4.77554676,5.3345245,5.5345245,5.4345245,1.1236886,4.77554676,5.3345245,1.1236886,4.77554676,5.3345245) > names(vals) <- LETTERS[1:16] > mp <- barplot(vals, ylim = c(0, 6)) > text(mp, vals, labels = vals, pos = 3) > > Is there any way to round up those numbers? > > I tried using > options(digits=2) > , and it does change the display of a table, but it does not influence the > barplot... Well, it does not affect as.character, nor should it. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch 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.
Re: [R] how to include bar values in a barplot?
On Wednesday 08 August 2007 00:40:56 Donatas G. wrote: > On Tuesday 07 August 2007 22:09:52 Donatas G. wrote: > > How do I include bar values in a barplot (or other R graphics, where this > > could be applicable)? > > > > To make sure I am clear I am attaching a barplot created with > > OpenOffice.org which has barplot values written on top of each barplot. > > After more than two hours search I finally found a solution: > http://tolstoy.newcastle.edu.au/R/help/06/05/27286.html Hey, the solution happens to be only partiall... If the values are not real numbers, and have a lot of digits after the dot, the graph might become unreadable... see this vals <- c(1,1.1236886,4.77554676,5.3345245,1,1.1236886,4.77554676,5.3345245,5.5345245,5.4345245,1.1236886,4.77554676,5.3345245,1.1236886,4.77554676,5.3345245) names(vals) <- LETTERS[1:16] mp <- barplot(vals, ylim = c(0, 6)) text(mp, vals, labels = vals, pos = 3) Is there any way to round up those numbers? I tried using options(digits=2) , and it does change the display of a table, but it does not influence the barplot... -- Donatas Glodenis http://dg.lapas.info __ R-help@stat.math.ethz.ch 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.
Re: [R] how to include bar values in a barplot?
On Tuesday 07 August 2007 22:09:52 Donatas G. wrote: > How do I include bar values in a barplot (or other R graphics, where this > could be applicable)? > > To make sure I am clear I am attaching a barplot created with > OpenOffice.org which has barplot values written on top of each barplot. After more than two hours search I finally found a solution: http://tolstoy.newcastle.edu.au/R/help/06/05/27286.html and http://tolstoy.newcastle.edu.au/R/help/05/09/12936.html However, what about percentage barcharts, such as this: http://dg.lapas.info/wp-content/barplot-lytys-G07_x_mean.png And maybe somebody knows how to get the legend of the bars in the barchart (again, see the example above)? -- Donatas Glodenis http://dg.lapas.info __ R-help@stat.math.ethz.ch 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.
Re: [R] how to include bar values in a barplot?
Generally adding the numbers to a graph accomplishes 2 things: 1) it acts as an admission that your graph is a failure 2) it converts the graph into a poorly laid out table (with a colorful and distracting background) In general it is better to find an appropriate graph that does convey the information that is intended or if a table is more appropriate, then replace it with a well laid out table (or both). Remember that the role of tables is to look up specific values and the role of graphs is to give a good overview. The books by William Cleveland and Tufte have a lot of good advice on these issues. Before asking how to get R to produce a graph that looks like one from a spreadsheet, you should study: http://www.burns-stat.com/pages/Tutor/spreadsheet_addiction.html and some of the links from there. You may also want to run the following in R: > library(fortunes) > fortune(120) In general I like OpenOffice, my one main complaint is that when faced with the decision between doing something right or the same way as microsoft, they have not always made the right decision. Hope this gives you something to think about, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Donatas G. > Sent: Tuesday, August 07, 2007 1:10 PM > To: r-help@stat.math.ethz.ch > Subject: [R] how to include bar values in a barplot? > > How do I include bar values in a barplot (or other R > graphics, where this could be applicable)? > > To make sure I am clear I am attaching a barplot created with > OpenOffice.org which has barplot values written on top of > each barplot. > > -- > Donatas Glodenis > http://dg.lapas.info > > __ > R-help@stat.math.ethz.ch 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. > __ R-help@stat.math.ethz.ch 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.
Re: [R] how to include bar values in a barplot?
See: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/56852.html On 8/7/07, Donatas G. <[EMAIL PROTECTED]> wrote: > On Tuesday 07 August 2007 22:09:52 Donatas G. wrote: > > How do I include bar values in a barplot (or other R graphics, where this > > could be applicable)? > > > > To make sure I am clear I am attaching a barplot created with > > OpenOffice.org which has barplot values written on top of each barplot. > > Here is the barplot mentioned above: > http://dg.lapas.info/wp-content/barplot-with-values.jpg > > it appeaars that this list does not allow attachments... > > -- > Donatas Glodenis > http://dg.lapas.info > > __ > R-help@stat.math.ethz.ch 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. > __ R-help@stat.math.ethz.ch 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.
Re: [R] how to include bar values in a barplot?
On Tuesday 07 August 2007 22:09:52 Donatas G. wrote: > How do I include bar values in a barplot (or other R graphics, where this > could be applicable)? > > To make sure I am clear I am attaching a barplot created with > OpenOffice.org which has barplot values written on top of each barplot. Here is the barplot mentioned above: http://dg.lapas.info/wp-content/barplot-with-values.jpg it appeaars that this list does not allow attachments... -- Donatas Glodenis http://dg.lapas.info __ R-help@stat.math.ethz.ch 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.
Re: [R] how to include bar values in a barplot?
Donatas G. wrote: > How do I include bar values in a barplot (or other R graphics, where this > could be applicable)? > > To make sure I am clear I am attaching a barplot created with OpenOffice.org > which has barplot values written on top of each barplot. > This causes an optical illusion in which the viewer adds some of the heights of the numbers to the heights of the bars. And in general dot charts are greatly preferred to bar plots, not the least because of their reduced ink:information ratio. -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@stat.math.ethz.ch 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.
[R] how to include bar values in a barplot?
How do I include bar values in a barplot (or other R graphics, where this could be applicable)? To make sure I am clear I am attaching a barplot created with OpenOffice.org which has barplot values written on top of each barplot. -- Donatas Glodenis http://dg.lapas.info __ R-help@stat.math.ethz.ch 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.