Hi,
Some time ago I asked about how to use comma as decimal separator in plots
and Mr. Paul Murrell wrote:
-------
You could try something with axis() and chartr(), like ...
par(mfrow=c(2,1))
plot(1:10/11, rep(1, 10), main="Standard X-Axis")
plot(1:10/11, rep(1, 10), main="Customised X-Axis", axes=F)
axis(1, at=pretty(1:10/11),
labels=chartr(".", ",",
as.character(pretty(1:10/11))))
axis(2)
box()
-------
This was very useful to me, but in the example:
x <- rnorm(50, mean=2, sd=0.1)
y <- rnorm(50, mean=2, sd=0.2)
plot(x,y)
axis(1,at=pretty(x),labels=chartr(".", ",",
as.character(pretty(x))))
axis(2,at=pretty(y),labels=chartr(".", ",",
as.character(pretty(y))))
I got an "2" in the middle of the "2.0". How could I avoid
it?
Thanks very much,
Antonio Olinto
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"Antonio Olinto" <aolinto at bignet.com.br> writes:> Hi, > > Some time ago I asked about how to use comma as decimal separator in plots > and Mr. Paul Murrell wrote: > ------- > You could try something with axis() and chartr(), like ... > par(mfrow=c(2,1)) > plot(1:10/11, rep(1, 10), main="Standard X-Axis") > plot(1:10/11, rep(1, 10), main="Customised X-Axis", axes=F) > axis(1, at=pretty(1:10/11), > labels=chartr(".", ",", as.character(pretty(1:10/11)))) > axis(2) > box() > ------- > > This was very useful to me, but in the example: > > x <- rnorm(50, mean=2, sd=0.1) > y <- rnorm(50, mean=2, sd=0.2) > plot(x,y) > axis(1,at=pretty(x),labels=chartr(".", ",", as.character(pretty(x)))) > axis(2,at=pretty(y),labels=chartr(".", ",", as.character(pretty(y)))) > > I got an "2" in the middle of the "2.0". How could I avoid it?You forgot to put axes=F inside plot() as Paul did, so you are overplotting the original axis labels, and you can see that in the other labels too since "," is slightly wider than ".". The "2" comes out because> pretty(y)[1] 1.6 1.8 2.0 2.2 2.4 2.6> as.character(pretty(y))[1] "1.6" "1.8" "2" "2.2" "2.4" "2.6" *** You'll probably prefer> format(pretty(y))[1] "1.6" "1.8" "2.0" "2.2" "2.4" "2.6" Another fine point is that (in my case---there's an rnorm() involved) the 2.6 value is outside the y-limits, so it looks strange if you omit the box(). pretty() will do that since it is required to cover the range of its argument, but the ylim on the plot is not required to cover pretty(y). This is easly fixed up in concrete cases, but I don't see a simple general solution except the slightly awkward py<-pretty(y) py<-py[py>=par("usr")[3]] py<-py[py<=par("usr")[4]]. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Antonio Olinto wrote:> > Hi, > > Some time ago I asked about how to use comma as decimal separator in plots[...]> This was very useful to me, but in the example: > > x <- rnorm(50, mean=2, sd=0.1) > y <- rnorm(50, mean=2, sd=0.2) > plot(x,y) > axis(1,at=pretty(x),labels=chartr(".", ",", as.character(pretty(x)))) > axis(2,at=pretty(y),labels=chartr(".", ",", as.character(pretty(y)))) > > I got an "2" in the middle of the "2.0". How could I avoid it?The mistake in your example is, that you draw two sets axes, one with dot and one with comma. You should suppress the default axes in the plot() function: plot(x,y, axes=FALSE) box() axis(1,at=pretty(x),labels=chartr(".", ",", as.character(pretty(x)))) axis(2,at=pretty(y),labels=chartr(".", ",", as.character(pretty(y)))) Thomas Petzoldt -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._