[R] barplot and ylim - display problems

Dan Bolser dmb at mrc-dunn.cam.ac.uk
Fri Feb 18 15:47:24 CET 2005



The following single line of code shows what I am trying to do, and the
problem I am having...

barplot(c(101,102,103),ylim=c(100,103))

The 'xaxis' is missing, and the grey bars 'fall off' the plot area. This
is generally ugly, and I would like to trim the bars (ideally they would
have a ragged appearance to show that I am 'zooming in').

I can see why what I am trying to do is conceptually a bit tricky, as the
yaxis needs to be closly inspected to see the data in its propper context.
This is simply fixed by showing...

barplot(c(101,102,103))

However, I want to first show the data in its propper context, then 'zoom
in' to highlight the difference between the bars. 

I tried covering up the bottom of the chart with a rect() command, but it
wont draw ouside the area highlighted with the box command, for example 


barplot(c(101,102,103),ylim=c(100,103))
box()
rect(0.7,0,1.9,102.5,col="white")

So I can't work out how to stop bars falling off the end of the plot, so
my labels are being written on the bars.

How can I fix this?




More information about the R-help mailing list