Hello,
The function barplot automatically creates a yaxis that doesn't necessarily cover the range of yvalues to be plotted. I know how to manually create my own yaxis so that it does cover the range, but I was wondering if there is some parameter to change so that the scale of the yaxis is automatically taller than the tallest bar. I thought setting xpd=F would do it, since it says that xpd determines whether bars will be plotted outside of the plotting region, but it had no effect, so I guess it must be dealing with something different. In the example below, the scale goes to 15 but the second bar goes to 16. In this case I would like the scale to go to 20. Thanks #example data data < c(12, 16) #none of the following are any different barplot(data) barplot(data, xpd=T) barplot(data, xpd=F) 
On Feb 1, 2010, at 7:11 PM, Jack Siegrist wrote: > > Hello, > > The function barplot automatically creates a yaxis that doesn't > necessarily > cover the range of yvalues to be plotted. I know how to manually > create my > own yaxis so that it does cover the range, but I was wondering if > there is > some parameter to change so that the scale of the yaxis is > automatically > taller than the tallest bar. > > I thought setting xpd=F would do it, since it says that xpd determines > whether bars will be plotted outside of the plotting region, but it > had no > effect, so I guess it must be dealing with something different. > > In the example below, the scale goes to 15 but the second bar goes > to 16. In > this case I would like the scale to go to 20. > > Thanks > > #example data > data < c(12, 16) > > #none of the following are any different > barplot(data) > barplot(data, xpd=T) > barplot(data, xpd=F) barplot(data, xpd=F, yaxp=c(0,max(data), 4) ) >  > View this message in context: http://n4.nabble.com/barplotyaxistooshorttp1459406p1459406.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/rhelp > PLEASE do read the posting guide http://www.Rproject.org/postingguide.html > and provide commented, minimal, selfcontained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/rhelp PLEASE do read the posting guide http://www.Rproject.org/postingguide.html and provide commented, minimal, selfcontained, reproducible code. 
On Feb 1, 2010, at 7:48 PM, David Winsemius wrote: > > On Feb 1, 2010, at 7:11 PM, Jack Siegrist wrote: > >> >> Hello, >> >> The function barplot automatically creates a yaxis that doesn't >> necessarily >> cover the range of yvalues to be plotted. I know how to manually >> create my >> own yaxis so that it does cover the range, but I was wondering if >> there is >> some parameter to change so that the scale of the yaxis is >> automatically >> taller than the tallest bar. >> >> I thought setting xpd=F would do it, since it says that xpd >> determines >> whether bars will be plotted outside of the plotting region, but it >> had no >> effect, so I guess it must be dealing with something different. >> >> In the example below, the scale goes to 15 but the second bar goes >> to 16. In >> this case I would like the scale to go to 20. >> >> Thanks >> >> #example data >> data < c(12, 16) >> >> #none of the following are any different >> barplot(data) >> barplot(data, xpd=T) >> barplot(data, xpd=F) > > barplot(data, xpd=F, yaxp=c(0,max(data), 4) ) That gets you a 16tick but not the desired range to 20. > barplot(data, yaxp=c(0,20, 4) ) #does not "work" in the senses that the range goes offplot and the "20" cannot be seen. > barplot(data, yaxp=c(0,20, 4), ylim=c(0,20) ) # "Works" >>  > David Winsemius, MD Heritage Laboratories West Hartford, CT ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/rhelp PLEASE do read the posting guide http://www.Rproject.org/postingguide.html and provide commented, minimal, selfcontained, reproducible code. 
In reply to this post by Jack Siegrist
Thanks for the replies.
Apparently you cannot adjust the extension factor used by yaxs (which is set at 4%), so what I did is wrote a function (barplotCovered) to get yaxis limits based on the range of the data and a userdefined axis expansion factor (axExFact). I included an example below in case someone else has this problem. # example data data < c(.10, .15, .52, .11) # calculate a maximum and minimum for the yscale: # takes the biggest datum: max(data) # then makes a buffer around it: max(data)*1.1 # then rounds that inflated number to one significant digit: signif(max(data)*1.1, digits=1) # then takes the max of that or 0 to allow for positive and negative numbers axExFact <1.1 ymax < max(c(0, signif(max(data)*axExFact, digits=1))) ymin < min(c(0, signif(min(data)*axExFact, digits=1))) # here is the plot barplot(data, ylim=c(ymin, ymax)) # another example data2 < c(10, 15, 52, 11) ymax2 < max(c(0, signif(max(data2)*1.1, digits=1))) ymin2 < min(c(0, signif(min(data2)*1.1, digits=1))) barplot(data2, ylim=c(ymin2, ymax2)) # here it is as a function barplotCovered < function(data, axExFact, ...){ ymax < max(c(0, signif(max(data)*axExFact, digits=1))) ymin < min(c(0, signif(min(data)*axExFact, digits=1))) barplot(data, ylim=c(ymin, ymax), ...) } # example using the function barplotCovered(data, axExFact=1.1, names.arg=c("a", "b", "c", "d"))  Jack Siegrist Graduate Program in Ecology & Evolution, and Department of Ecology, Evolution, & Natural Resources, Rutgers University, New Brunswick, NJ 08901

Free forum by Nabble  Edit this page 