[R] barplot + plot
Marc Schwartz
mschwartz at medanalytics.com
Mon Oct 14 16:11:27 CEST 2002
> -----Original Message-----
> Dear all,
> I've got another question,
> By default barplot and plot seem to produce slightly different y-axis.
> The problem I've got is when using a mix figure with both, barplot and
> plot. For example:
>
> barplot(1:5, ylim=c(0, 6))
> par(new= T)
> plot(1:5, 9:5, type="b", axes=FALSE, ylim=c(0,9))
> axis(4)
> box()
>
> note that both plots (barplot and plot) should start at 0, but the
exact
> starting at 0 is only produced with barplot but not with plot.
> Is there a way to make the two axes more coherent, that is both
starting
> at the exact 0 or both starting like the plot?
>
> Thanks a lot for any suggestion
>
> Juli
Juli,
The difference is in the way that barplot() and plot() draw the style of
axes by default.
In barplot(), which you call first, it sets par(yaxs = "i") explicitly
in the code.
Unless you change it, plot() uses the default parameter value of
par(yaxs = "r"), which draws a different style of axis.
If you add:
par(yaxs = "i") before your plot(...) line, you will get a consistent 0
starting point.
See ?par and scroll to par(xaxs), which describes the style of axes
available for both x and y.
Thus, your example code should look like:
barplot(1:5, ylim=c(0, 9))
par(new= T)
par(yaxs = "i")
plot(1:5, 9:5, type="b", axes=FALSE, ylim=c(0,6))
axis(4)
box()
I presume that you explicitly want the y axis ranges to be different.
If not, be sure to set ylim to the same values.
HTH.
Marc Schwartz
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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