[R] Possible x-axis label bug in barplot() when "plot = F"
MSchwartz at medanalytics.com
Mon May 20 17:27:22 CEST 2002
> The help page says "plot: logical. If FALSE, nothing is plotted."
> barplot() just calculates the midpoints it would use in the case of
> In your second example a device is opened by plot.new(), which has the
> default user coordinates par("usr")
>  -0.04 1.04 -0.04 1.04
> and the result of your call to axis() is expected.
> So plot.new() is useless in either of your examples. In the first one
> barplot() generates a new plot anyway, in the second example it makes
> axis() work on a way, you don't want it to work ...
> The real question (at least for me) is: What are you going to do with
> your code?
> Uwe Ligges
Thanks for your reply.
I am attempting to parallel (using barplot() ) an example in the
demo(graphics) code which enables the plot region to be colored
differently than the margins and allows for flexibility in defining the
axis labels, etc.
The demo code (which is for the "Level of Interest in R" line graphic)
shows that the plot region can be colored differently by setting the
background color using par(bg = "color") and then calling plot(x, type =
"n", axes = FALSE, ann = FALSE) so that nothing is actually plotted.
I presume that this sets up the coordinate system for the graphic, such
that subsequent graphic components can then be placed within the same
relative coordinate system area. Perhaps that is not a valid presumption
on my part.
A call is then made to rect() using corner positions from par("usr"),
which allows for the plot region to be filled with a different color
than the margin.
Subsequent calls are made to plot the data points, lines, titles, etc.
so that they do not overwrite the newly colored plot region.
I was trying to parallel this using barplot() by doing the following
(ignore the color combinations for now):
> par(bg = "blue")
> midpts <- barplot(1:10, axes = F, axisnames = F)
> usr <- par("usr")
> rect(usr, usr, usr, usr, col = "white")
> abline(h = 1:10, lty = "dotted")
> rect(midpts - .4, 0, midpts + .4, 1:10, col = "yellow")
> axis(1, at = midpts, col.axis = "white")
> axis(2, 1:10, col.axis = "white", las = 1)
> title("This Is A Test\nShowing Different Plot Region Color", col.main
The above code actually works fine in terms of the final result for
demonstration purposes to give you a sense of what I am trying to do. I
was just attempting to parallel the aforementioned plot() code so as to
not actually plot the graphic, overwrite it with the first call to
rect() and then draw subsequent components individually.
Was I wrong to attempt to take the same approach?
I actually get errors on subsequent graphic calls, if I try to use
barplot(...., plot = F) first, without having first called plot.new().
Again, perhaps I am missing something fundamental here.
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