[R] cutting barplots at e.g. 50%

Ott Toomet siim at obs.ee
Mon Mar 18 09:54:17 CET 2002


Hi,

I have not noticed any reply to your question (perhaps my fault), so I
suggest a workaround.

On Fri, 15 Mar 2002, Jan Malte Wiener wrote:

  |hi,
  |i want to plot percentage values using barplot. everything works fine so 
  |far. giving a chance level of 50% i want to plot only the area above 50 
  |percent.
  |i can of course cut  using  ylim=c(50,100) but this does not work 
  |properly since i also see some of the area below 50%.

Actually, it seems strange for me that R (1.4.0) draws bars outside the plot
are.  But you can explicitly subtract 50 and then choose either the result
or 0.  To avoid the axis showing values 0..50, you should draw the axis
yourself using axis and labels where you have added 50.

A following example worked for me:

proc <- runif(10,0,100)
lbl <- as.character(formatC(proc, digits=4))
height <- pmax(proc - 50, 0)
spread <- range(height)
par(las=2)
barplot(height, names.arg=lbl,axes=F)
axis(2, at=pretty(spread), labels=as.character(pretty(spread) + 50))

You can also consider using

barplot(proc[proc>50], names.arg=lbl[proc>50])

but I do not think that is what you want.

Cheers,

Ott Toomet

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list