Re: [R] barplot2, gap.barplot
Marc A. Rohling wrote: Hello, I try to handle a simple bar-plot, but it turns out to be not as simple as I thought. ... As you can see, because of the 4th bar (value 45), the other bars look a little bit tiny: there is too much white-space. What I need to handle this problem is a function to insert a gap. I tried to use gap.barplot, but unfortunately, it cannot handle any of the parameters I need from the barplot2-function. After days of missing effort, I am sick of this problem. Is there a solution? Hi Marc1, As Marc2 said, the use of discontinuous axes in plots is a contentious one. No, I did not try to make gap.barplot compatible with barplot2 as the two seem to have different aims. gap.barplot is one solution to the troublesome issue of the outlier. What I would suggest as a one-off solution (to the horror of some) is to subtract, say, 25 from the outlier value, do the barplot, then: par(xpd=TRUE) axis.break(2,21,style=gap) text(barpos[4],24,48.6) I realize that your plot is more complex (I don't have gplots, etc. installed so I can't reproduce it at the moment), but that might give you something with which to work. Jim __ 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] barplot2, gap.barplot
3. Depending on the nature of your data, if the extreme value is representative of an important marked difference relative to the other values, then I don't particularly find the 'look' of the plot to be overly problematic. It does appropriately emphasize the large difference. On the other hand, you might want to consider using a log scale on the y axis as an alternative to an axis gap. This would be a reasonable approach to plotting values that have a notable difference in range. If you do this, note that you would need to ensure that all y values are 0 (ie. y axis range minimum, lower bounds of CI's, etc.) since: log10(0) [1] -Inf Of course, you can't do this with a bar plot, because bars should be anchored at 0. Hadley __ 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] barplot2, gap.barplot
On Fri, 2007-03-02 at 08:53 -0600, hadley wickham wrote: 3. Depending on the nature of your data, if the extreme value is representative of an important marked difference relative to the other values, then I don't particularly find the 'look' of the plot to be overly problematic. It does appropriately emphasize the large difference. On the other hand, you might want to consider using a log scale on the y axis as an alternative to an axis gap. This would be a reasonable approach to plotting values that have a notable difference in range. If you do this, note that you would need to ensure that all y values are 0 (ie. y axis range minimum, lower bounds of CI's, etc.) since: log10(0) [1] -Inf Of course, you can't do this with a bar plot, because bars should be anchored at 0. Both barplot() and barplot2() support log scaling for both x and y axes. In both functions, the default axis minimum for the 'height' axis (y by default, x if 'horizontal = TRUE') will be 0.9 * min(height) to avert log10(0) related issues. Errors will be issued otherwise if any values of 'height' are = 0 or 'ylim'/'xlim' args are similarly set. Using a function that Martin had posted some time ago, to nicely format the axis labels: axTexpr - function(side, at = axTicks(side, axp=axp, usr=usr, log=log), axp = NULL, usr = NULL, log = NULL) { ## Purpose: Do a 10^k labeling instead of a ek ## this auxiliary should return 'at' and 'label' (expression) ## -- ## Arguments: as for axTicks() ## -- ## Author: Martin Maechler, Date: 7 May 2004, 18:01 eT - floor(log10(abs(at)))# at == 0 case is dealt with below mT - at / 10^eT ss - lapply(seq(along = at), function(i) if(at[i] == 0) quote(0) else substitute(A %*% 10^E, list(A=mT[i], E=eT[i]))) do.call(expression, ss) } x - 10 ^ (0:10) barplot(x, log = y, yaxt = n) axis(2, at = x, labels = axTexpr(2), las = 2) box() HTH, Marc __ 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] barplot2, gap.barplot
On 3/2/07, Marc Schwartz [EMAIL PROTECTED] wrote: On Fri, 2007-03-02 at 08:53 -0600, hadley wickham wrote: 3. Depending on the nature of your data, if the extreme value is representative of an important marked difference relative to the other values, then I don't particularly find the 'look' of the plot to be overly problematic. It does appropriately emphasize the large difference. On the other hand, you might want to consider using a log scale on the y axis as an alternative to an axis gap. This would be a reasonable approach to plotting values that have a notable difference in range. If you do this, note that you would need to ensure that all y values are 0 (ie. y axis range minimum, lower bounds of CI's, etc.) since: log10(0) [1] -Inf Of course, you can't do this with a bar plot, because bars should be anchored at 0. Both barplot() and barplot2() support log scaling for both x and y axes. In both functions, the default axis minimum for the 'height' axis (y by default, x if 'horizontal = TRUE') will be 0.9 * min(height) to avert log10(0) related issues. Errors will be issued otherwise if any values of 'height' are = 0 or 'ylim'/'xlim' args are similarly set. I think that's a pretty bad idea - in a bar plot you are comparing the ratio of heights of the bars, not the absolute heights. It's the same reason it's a bad idea to have a bar graph with a non-0 y-axis - it's misleading. Hadley __ 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] barplot2, gap.barplot
On Fri, 2007-03-02 at 10:07 -0600, hadley wickham wrote: On 3/2/07, Marc Schwartz [EMAIL PROTECTED] wrote: On Fri, 2007-03-02 at 08:53 -0600, hadley wickham wrote: 3. Depending on the nature of your data, if the extreme value is representative of an important marked difference relative to the other values, then I don't particularly find the 'look' of the plot to be overly problematic. It does appropriately emphasize the large difference. On the other hand, you might want to consider using a log scale on the y axis as an alternative to an axis gap. This would be a reasonable approach to plotting values that have a notable difference in range. If you do this, note that you would need to ensure that all y values are 0 (ie. y axis range minimum, lower bounds of CI's, etc.) since: log10(0) [1] -Inf Of course, you can't do this with a bar plot, because bars should be anchored at 0. Both barplot() and barplot2() support log scaling for both x and y axes. In both functions, the default axis minimum for the 'height' axis (y by default, x if 'horizontal = TRUE') will be 0.9 * min(height) to avert log10(0) related issues. Errors will be issued otherwise if any values of 'height' are = 0 or 'ylim'/'xlim' args are similarly set. I think that's a pretty bad idea - in a bar plot you are comparing the ratio of heights of the bars, not the absolute heights. It's the same reason it's a bad idea to have a bar graph with a non-0 y-axis - it's misleading. Hadley, I might note that even lattice will do this, arguably easier than barplot[2](): library(lattice) x - 10 ^ (0:10) barchart(x ~ 0:10, horizontal = FALSE, scales = list(y = list(log = 10))) Is it the right thing to do? I'll leave that for others to debate. I have stronger feelings on the 'gapped axis' issue. I don't tend to use bar plots too much myself any longer and it all depends upon the audience. There have been requests for log scales on barplots on the R lists going back several years, which is one of the reasons that I wrote barplot2() some years ago. It was also one of my first exercises in gaining a lower level understanding of R's graphics models. The 'log' and 'add' arguments and related code from barplot2() were then included in R's barplot() in version 2.2.0, I believe by Paul. HTH, Marc __ 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] barplot2, gap.barplot
On 3/2/07, Marc Schwartz [EMAIL PROTECTED] wrote: On Fri, 2007-03-02 at 10:07 -0600, hadley wickham wrote: On 3/2/07, Marc Schwartz [EMAIL PROTECTED] wrote: On Fri, 2007-03-02 at 08:53 -0600, hadley wickham wrote: 3. Depending on the nature of your data, if the extreme value is representative of an important marked difference relative to the other values, then I don't particularly find the 'look' of the plot to be overly problematic. It does appropriately emphasize the large difference. On the other hand, you might want to consider using a log scale on the y axis as an alternative to an axis gap. This would be a reasonable approach to plotting values that have a notable difference in range. If you do this, note that you would need to ensure that all y values are 0 (ie. y axis range minimum, lower bounds of CI's, etc.) since: log10(0) [1] -Inf Of course, you can't do this with a bar plot, because bars should be anchored at 0. Both barplot() and barplot2() support log scaling for both x and y axes. In both functions, the default axis minimum for the 'height' axis (y by default, x if 'horizontal = TRUE') will be 0.9 * min(height) to avert log10(0) related issues. Errors will be issued otherwise if any values of 'height' are = 0 or 'ylim'/'xlim' args are similarly set. I think that's a pretty bad idea - in a bar plot you are comparing the ratio of heights of the bars, not the absolute heights. It's the same reason it's a bad idea to have a bar graph with a non-0 y-axis - it's misleading. Hadley, I might note that even lattice will do this, arguably easier than barplot[2](): library(lattice) x - 10 ^ (0:10) barchart(x ~ 0:10, horizontal = FALSE, scales = list(y = list(log = 10))) Is it the right thing to do? I'll leave that for others to debate. I have stronger feelings on the 'gapped axis' issue. I think this is up there with double and gapped axes. Although it's much easier to resolve - just use a dot plot instead (which is generally a pretty good rule whenever you want to use a bar plot) There have been requests for log scales on barplots on the R lists going back several years, which is one of the reasons that I wrote barplot2() some years ago. It was also one of my first exercises in gaining a lower level understanding of R's graphics models. People are always asking for things they don't really want! ;) I (obviously) have pretty strong feelings about graphics - I don't think you should be able to create meaningless (in some sense) graphics. Hadley __ 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] barplot2, gap.barplot
On Fri, 2007-03-02 at 14:57 -0600, hadley wickham wrote: On 3/2/07, Marc Schwartz [EMAIL PROTECTED] wrote: On Fri, 2007-03-02 at 10:07 -0600, hadley wickham wrote: On 3/2/07, Marc Schwartz [EMAIL PROTECTED] wrote: On Fri, 2007-03-02 at 08:53 -0600, hadley wickham wrote: 3. Depending on the nature of your data, if the extreme value is representative of an important marked difference relative to the other values, then I don't particularly find the 'look' of the plot to be overly problematic. It does appropriately emphasize the large difference. On the other hand, you might want to consider using a log scale on the y axis as an alternative to an axis gap. This would be a reasonable approach to plotting values that have a notable difference in range. If you do this, note that you would need to ensure that all y values are 0 (ie. y axis range minimum, lower bounds of CI's, etc.) since: log10(0) [1] -Inf Of course, you can't do this with a bar plot, because bars should be anchored at 0. Both barplot() and barplot2() support log scaling for both x and y axes. In both functions, the default axis minimum for the 'height' axis (y by default, x if 'horizontal = TRUE') will be 0.9 * min(height) to avert log10(0) related issues. Errors will be issued otherwise if any values of 'height' are = 0 or 'ylim'/'xlim' args are similarly set. I think that's a pretty bad idea - in a bar plot you are comparing the ratio of heights of the bars, not the absolute heights. It's the same reason it's a bad idea to have a bar graph with a non-0 y-axis - it's misleading. Hadley, I might note that even lattice will do this, arguably easier than barplot[2](): library(lattice) x - 10 ^ (0:10) barchart(x ~ 0:10, horizontal = FALSE, scales = list(y = list(log = 10))) Is it the right thing to do? I'll leave that for others to debate. I have stronger feelings on the 'gapped axis' issue. I think this is up there with double and gapped axes. Although it's much easier to resolve - just use a dot plot instead (which is generally a pretty good rule whenever you want to use a bar plot) Indeed. Beyond Tufte and Cleveland, a while back I had been doing some searches on related matters and happened to come across this article by Naomi Robbins: http://www.b-eye-network.com/newsletters/ben/2468 You may find the graphics somewhat familiar looking... There have been requests for log scales on barplots on the R lists going back several years, which is one of the reasons that I wrote barplot2() some years ago. It was also one of my first exercises in gaining a lower level understanding of R's graphics models. People are always asking for things they don't really want! ;) Quite... :-) I (obviously) have pretty strong feelings about graphics - I don't think you should be able to create meaningless (in some sense) graphics. But, how do you really feel? ;-) Regards, Marc __ 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] barplot2, gap.barplot
Hello, I try to handle a simple bar-plot, but it turns out to be not as simple as I thought. 1) I have created a .dat-File, e.g. test.dat: DATADATA-SEM 2.2 0.32 6.2 1.30 12.71.61 48.63.08 4.1 0.86 4.5 0.32 1.5 1.13 1.2 1.08 The first row is the data represented by bars. The second row deals with the Standard Error of Mean. The lines correspond to time-intervals of experiments. 2) I now wrote this R-Script: #=BEGIN= # example.R library(gdata) library(gtools) library(gmodels) library(gplots) library(plotrix) data - matrix(scan(./plot/example.dat, skip=1), ncol=2, nrow=8, byrow=TRUE, dimnames=list(c(1, 2, 3, 4, 5, 6, 7, 8),c(DATA, DATA-SEM))) conf_l - data[, 1] conf_u - data[, 1] + data[, 2] op - par(no.readonly = TRUE) par(lab=c(8,10,7)) barplot2( height=data[, 1], width=1, space=1, col='black', border='black', angle=0, density=NULL, ylim=c(-2,55), xpd=FALSE, axes=TRUE, las=1, ci.u=conf_u, ci.l=conf_l, plot.ci=TRUE, ci.color=black, ci.lty=solid, ci.lwd=1, horiz=FALSE, main=Header, ylab=, xlab=\nduration of treatment, plot.grid=TRUE) par(op) #END= As you can see, because of the 4th bar (value 45), the other bars look a little bit tiny: there is too much white-space. What I need to handle this problem is a function to insert a gap. I tried to use gap.barplot, but unfortunately, it cannot handle any of the parameters I need from the barplot2-function. After days of missing effort, I am sick of this problem. Is there a solution? Thanks for your help, Marc __ 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] barplot2, gap.barplot
On Thu, 2007-03-01 at 14:56 +0100, Marc A. Rohling wrote: Hello, I try to handle a simple bar-plot, but it turns out to be not as simple as I thought. 1) I have created a .dat-File, e.g. test.dat: DATA DATA-SEM 2.2 0.32 6.2 1.30 12.7 1.61 48.6 3.08 4.1 0.86 4.5 0.32 1.5 1.13 1.2 1.08 The first row is the data represented by bars. The second row deals with the Standard Error of Mean. The lines correspond to time-intervals of experiments. 2) I now wrote this R-Script: #=BEGIN= # example.R library(gdata) library(gtools) library(gmodels) library(gplots) library(plotrix) data - matrix(scan(./plot/example.dat, skip=1), ncol=2, nrow=8, byrow=TRUE, dimnames=list(c(1, 2, 3, 4, 5, 6, 7, 8),c(DATA, DATA-SEM))) conf_l - data[, 1] conf_u - data[, 1] + data[, 2] op - par(no.readonly = TRUE) par(lab=c(8,10,7)) barplot2( height=data[, 1], width=1, space=1, col='black', border='black', angle=0, density=NULL, ylim=c(-2,55), xpd=FALSE, axes=TRUE, las=1, ci.u=conf_u, ci.l=conf_l, plot.ci=TRUE, ci.color=black, ci.lty=solid, ci.lwd=1, horiz=FALSE, main=Header, ylab=, xlab=\nduration of treatment, plot.grid=TRUE) par(op) #END= As you can see, because of the 4th bar (value 45), the other bars look a little bit tiny: there is too much white-space. What I need to handle this problem is a function to insert a gap. I tried to use gap.barplot, but unfortunately, it cannot handle any of the parameters I need from the barplot2-function. After days of missing effort, I am sick of this problem. Is there a solution? Thanks for your help, Marc Marc, A few comments: 1. I am not a big fan of axis gaps, as they tend to alter the perception of the differences in the values. You will find similar comments in books by Cleveland et al on statistical graphs. 2. For continuous data, I would similarly argue against using barplots and consider a regular point plot with error bars. This can be done easily with the combination of plot() and arrows() in base R graphics or plotCI() in 'gplots'. 3. Depending on the nature of your data, if the extreme value is representative of an important marked difference relative to the other values, then I don't particularly find the 'look' of the plot to be overly problematic. It does appropriately emphasize the large difference. On the other hand, you might want to consider using a log scale on the y axis as an alternative to an axis gap. This would be a reasonable approach to plotting values that have a notable difference in range. If you do this, note that you would need to ensure that all y values are 0 (ie. y axis range minimum, lower bounds of CI's, etc.) since: log10(0) [1] -Inf I don't have the plotrix package installed, but the docs for it indicate that the gap.barplot() function does not return any values, such as the bar midpoints, which is the case for barplot() and barplot2(). This would suggest that Jim did not anticipate the need to add additional plot components to the bars. Lacking this, you have have to review the function source code to ascertain how Jim is drawing the bars (presumably using rect() ) and figure out the x axis values for the bar midpoints so that you could then add the CI's. Of course, you would have to consider the axis gaps here as well, making it a bit more cumbersome. As I note above, however, I would advise against this approach. HTH, Marc Schwartz __ 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.