I’m making a plot in R I’d like to have a symbol appear at a specific point (say, alpha) on my y axis. My x axis uses a log-scale so I don’t think I can use the xy coordinates (0, alpha) to plot the point (I may be wrong).
I’ve tried something like this:
W.range <- range(W)
Z.range <- range(Z1, Z2)
# Draw Empty Graph
plot(W.range, Z.range, type="n", log="x")
# First Curve
lines(W, Z1, type="l", lty=1, lwd=1.5, col=1)
# Second Curve
lines(W, Z2, type="l", lty=2, lwd=1.5, col=2)
# Plot Single Point on vertical axis at level alpha (for some constant alpha)
points(x=0, y=alpha, pch=1, col=1)
However, I get errors relating to the x=0 coordinate. Advice? As always, I appreciate the suggestions.
This should work, subbing in your own data as appropriate:
To understand what I did here, have a look at
?par, which I use here both to query and to set graphical parameters.In particular, here is the description of
par("usr"), from the help file linked above:The x-coordinates returned by
usrare in terms of the log-transformed values of x. Thus, to get a point placed on the y-axis, you need to give it an x coordinate such that it’s log (base 10) is equal to the location of the y-axis, expressed in user coordinates.par("usr")[1]gets you the location of the lower limit of the x-axis:10^(par("usr")[1]gets you the x-value that will be plotted to just that part of the x-axis.