Skip to content

cutting barplots at e.g. 50%

3 messages · Jan M. Wiener, Uwe Ligges, Ott Toomet

#
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%.

thanks for suggestions,
jan


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Jan Malte Wiener wrote:
Looks like a bug (the problem ist the setting of 'xpd').

What you can do is:
At first substract 50 from your data, then add the axis manually:

 x <-  seq(50,100,10) 	# your data
 xn <- x - 50		# substract 50
 barplot(xn, yaxt="n")  # no axis (would be wrong)
 axis(2, at=0:5 * 10, labels=5:10 * 10) # so adding it manually

Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
2 days later
#
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._