C Chang
2004-Feb-03 20:50 UTC
[R] how to change one of the axis to normal probability scale
Hi, I would like to plot a graph with one axis in log scale and the other in normal probability scale using R. I cannot change the axis scale to probability scale. What can be a solution? Thanks. CT
Duncan Murdoch
2004-Feb-03 21:42 UTC
[R] how to change one of the axis to normal probability scale
On 03 Feb 2004 20:50:36 +0000, C Chang <cc164 at york.ac.uk> wrote :>Hi, > >I would like to plot a graph with one axis in log scale and the other in >normal probability scale using R. I cannot change the axis scale to >probability scale. What can be a solution? Thanks.You should plot with "axes=F", then add the axes manually. For example, x <- sort(rnorm(100)) y <- sort(rnorm(100)) plot(x,y,axes=F) box() at <- c(0.01,0.1,0.5,0.9,0.99) axis(1,at=qnorm(at),labels=at) axis(2,at=qnorm(at),labels=at) box() (At least I think that's a "normal probability scale", but you better check against your own definition.) Duncan Murdoch
Charles Annis, P.E.
2004-Feb-03 22:41 UTC
[R] how to change one of the axis to normal probability scale
Dear C. Chang:
It's very helpful to draw your own grid in situations like this. I have
included the code for mine below.
First some disclaimers:
1) The probability axis goes from p=1.e-7 to p=1-1.e-7, ridiculous
extrapolations by most accounts. However, the engineers with whom I work do
this extrapolation, often unthinkingly. At least plotting on this grid
forces them to consider what they are doing and how much (or little) data
they have to substantiate it. You can fix this easily in your routine, by
only considering, say, p=0.001, to p=0.999.
2) The grid looks great as drawn but scales poorly because the location of
labels etc. are absolute rather than relative or some cobbled combination of
these. Since it does what I need, I use it. In your grid you may want to
make it easier to scale.
3) Notice that the plot is set up like this:
plot(NA, NA, xlim=c(3, 7), ylim=c(z.min, z.max), ...
so that you will be plotting on a Cartesian grid in x-units of log10() and
y-units of qnorm()
Anyway here's the code. Watch out for superfluous carriage-returns inserted
by the mail handler.
##### R code to draw a lognormal CDF grid. #####
lognormal.CDF.fn <- function(x.axis.title="Nf, Cycles"){
# lognormal CDF grid
# First draw the grid with no points.
# The x-axis is log cycles. The y-axis, although labled probability, is
ploted as normal z units.
z.min <- -5.5
z.max <- -z.min
z.norm <- seq(z.min, z.max, length=101)
plot(NA, NA, xlim=c(3, 7), ylim=c(z.min, z.max), type="n",
xaxt="n",
yaxt="n", frame = FALSE, xlab = "", ylab = "Cumulative
Probability (Fraction
less than N)")
#
# Draw the x-axis
axis(side = 1, labels = FALSE, at = c(3, 4, 5, 6, 7), line = 0., tick=TRUE,
outer = FALSE)
text(x=c(3, 4, 5, 6, 7), y=rep(z.min-1.0, 5), rep("10", 5), xpd =
NA,
cex=1.)
text(x=c(3, 4, 5, 6, 7)+ 0.1, y=rep(z.min-0.8, 5)+0.08, c("3",
"4", "5",
"6", "7"), xpd = NA, cex=0.8)
text(x=5.05, y=z.min-1.6, x.axis.title, xpd=NA, cex=1.)
# Draw the interior log tick marks
for (i in 3:6){
axis(side=1, at=log10(c(2, 3, 4, 5, 6, 7, 8, 9))+ i, cex=1, labels=NA,,
line = 0, tck = -0.01)
text(x=log10(c(2, 3, 4, 5, 6, 7, 8))+ i, y=rep(z.min-0.7, 7), c("2",
"3",
"4", "5", "6", "7", "8"), xpd
= NA, cex=0.7)
}
#
# Draw the y-probability axis
probs <- c(1e-7, 1e-6, 1e-5, 1e-4, 0.001, 0.002, 0.005, 0.01, 0.02, 0.05,
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95, 0.98, 0.99, 0.995, 0.998,
0.999, 0.9999, 0.99999, 0.999999, 0.9999999)
z.vals <- qnorm(probs)
axis(side=2, at=z.vals , labels=NA, line = 0, tck = -0.01)
text(x=rep(3.-0.4, 4), y= -0.1+qnorm(c(1e-7, 1e-6, 1e-5, 1e-4)), cex=0.8,
xpd = NA, labels=rep("10", 6))
text(x=rep(3.-0.3 , 4), y= 0.1+qnorm(c(1e-7, 1e-6, 1e-5, 1e-4)), cex=0.6,
xpd = NA,labels=c("-7", "-6", "-5",
"-4"))
text(x=rep(3.-0.25, 6), y= qnorm(c(0.001, 0.01, 0.1, 0.5, 0.9, 0.99,
0.999)), cex=0.7, xpd = NA,labels=c("0.001", "0.01",
"0.1", "0.5", "0.9",
"0.99", "0.999"), adj=1)
text(x=rep(3.-0.4, 4), y= -0.1-qnorm(c(1e-7, 1e-6, 1e-5, 1e-4)), cex=0.8,
xpd = NA, labels=rep("1-10", 6))
text(x=rep(3.-0.27 , 4), y= 0.1-qnorm(c(1e-7, 1e-6, 1e-5, 1e-4)),
cex=0.6, xpd = NA,labels=c("-7", "-6", "-5",
"-4"))
box()
}
### Test it
lognormal.CDF.fn()
###################################################################
Charles Annis, P.E.
Charles.Annis at StatisticalEngineering.com
phone: 561-352-9699
eFax: 503-217-4849
http://www.StatisticalEngineering.com
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of C Chang
Sent: Tuesday, February 03, 2004 3:51 PM
To: r-help at stat.math.ethz.ch
Subject: [R] how to change one of the axis to normal probability scale
Hi,
I would like to plot a graph with one axis in log scale and the other in
normal probability scale using R. I cannot change the axis scale to
probability scale. What can be a solution? Thanks.
CT
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
R-Users,
As a relatively new user of R, I have a quick (and probably
simple) question about using write(). I have a population simulation that
I am running and I want to output a set of variables for each run of the
simulation into a text file for use in another program. However, whenever
I attempt to use write(), the only output that I am able to get is the
final numbers from the simulation.
for example:
x <- 5
for (i in 1:10){
z <- x+i
print(z)
write(z, "c:/test.txt")
}
In this simple case, with print(z) I can see that z has what I am looking
for, but all that is output for the write statement is 15; While this is
simplified, it shows my problem.
I searched the help files, and on the R website, but I could not find
anything addressing this. I suspect that it is my lack of knowledge and I
am missing something obvious (or should be using write.table). If anyone
could point me in the right direction I would appreciate it.
Thanks,
Bret Collier
Univ. Arkansas
Bret Collier wrote:> R-Users, > As a relatively new user of R, I have a quick (and probably > simple) question about using write(). I have a population simulation > that I am running and I want to output a set of variables for each run > of the simulation into a text file for use in another program. However, > whenever I attempt to use write(), the only output that I am able to get > is the final numbers from the simulation. > > for example: > > x <- 5 > for (i in 1:10){ > z <- x+i > print(z) > write(z, "c:/test.txt") > }For each i in 1:10 you are printing z to the console and writing z into a file test.txt. Note that you only see the last z in the file, since it has been been overwritten several times, while the output on your console produced by print() has not been not overwritten. Uwe Ligges> In this simple case, with print(z) I can see that z has what I am > looking for, but all that is output for the write statement is 15; > While this is simplified, it shows my problem. > > I searched the help files, and on the R website, but I could not find > anything addressing this. I suspect that it is my lack of knowledge and > I am missing something obvious (or should be using write.table). If > anyone could point me in the right direction I would appreciate it. > > Thanks, > > Bret Collier > Univ. Arkansas > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html