Skip to content

x axis point labels

4 messages · Michaell Taylor, Peter Dalgaard, Mark Myatt

#
I am attempting to manually specify x axis value labels (NOT x axis label as 
in xlab) on a density plot.  Generally speaking, I would like to erase the 
default x axis point labels and replace them with arbitrary x axis point 
labels relating to specific CDF points.

I am sure this can be done, but it isn't obvious to me how.  Has anyone done 
this before?

My R code follows if it helps (new to R so please excuse any awkwardness that 
you notice.)

plot(density(gdp), main="Probability Distribution\n of 2002 US GDP 
Forecast",lwd=3, 
	xlim=c(-9,9), ylim=c(0,.3),xlab="Percent Real GDP Growth")
par(new=T)
newline _ cbind(c(gdp[5000/2],gdp[5000/2]),c(0,.25)) 
newline1 _ cbind(c(gdp[.05*5000],gdp[.05*5000]),c(0,.15)) 
newline2 _ cbind(c(gdp[.95*5000],gdp[.95*5000]),c(0,.15)) 
newline3 _ cbind(c(gdp[.99*5000],gdp[.99*5000]),c(0,.1)) 
newline4 _ cbind(c(gdp[.01*5000],gdp[.01*5000]),c(0,.1)) 
lines(newline, lwd=2)
lines(newline1)
lines(newline2)
lines(newline3)
lines(newline4)
text(gdp[5000/2],.29,"Median\nForecast")
text(gdp[5000*.05],.19,"0.05 Prob.\nForecast")
text(gdp[5000*.95],.24,"0.95 Prob.\nForecast")
text(gdp[5000*.99],.14,"0.99 Prob.\nForecast")
text(gdp[5000*.01],.14,"0.01 Prob.\nForecast")


===========================

Michaell Taylor, PhD

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Michaell Taylor <michaell.taylor at reis.com> writes:
Yes. Try this, one line at the time:

plot(0, axes=FALSE)
axis(1)
axis(2)
box()

Then look at the documentation for axis()
Doesn't really. You might want to lose the "_" for assignment, though.
It is a relic that several people want to see disappear in future
versions, so do youself a favour and use "<-".
#
Sorry,

I hit the send button and then immediately saw the axes=FALSE and manual axis 
commands.

Problem solved.

Michaell
On Monday 24 September 2001 16:58, Michaell Taylor wrote:
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Michaell Taylor <michaell.taylor at reis.com> writes:
Just wrestled with something like this myself and this is the way I did
it:

        1. Set the lab parameter to the number of tickmarks you want on
        the x and y axes. If you have a vector of labels called (e.g.)
        my.labels then use something like:

                par(lab = c(length(my.labels, 5, 7))

        2. Plot without axes (i.e. add the parmeater "axes = false" to
        the plotting function you use top create your chart).

        3. Add axes using the axis() function:

                axis(side = 1, labels = mylabels)
                axis(side = 2)

Here is an example using a time series ... you should get the idea:

        Months <- c("May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
                    "Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                    "Jul")
        WheatI <- c(0.00, 0.97, 0.97, 0.87, 0.74, 0.64, 0.51, 0.28, 
                    0.26, 0.18, 0.00, 0.00, 0.00, 0.00, 0.00)

        par(lab = c(length(Months), 3, 7))     
        plot(WheatI * 100, type = "s", ylim = c(0, 100), xlab = "",
             ylab = "%", main = "Irrigated Wheat", bty = "n",
             axes = FALSE)
        axis(side = 1, labels = Months)
        axis(side = 2)

I hope that helps.

Mark


--
Mark Myatt


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._