[R] using axis with newline characters

Paul Murrell p.murrell at auckland.ac.nz
Wed May 29 03:15:43 CEST 2002


> Wondering if I missed anything or if that's a problem with R:
> I want to have many x axis tickmarks and labels such that it makes sense to put them on multiple "lines".
> The newline character seems to be ignored though for axis labels:
> plot(1:33, axes=F)
> axis(1, 9, 9)
> axis(1, 11, "\n11")
> axis(1)

The problem here is that axis() (and mtext()) control the vertical
adjustment of text (based on the setting of par(las)).  The whole piece
of text "\n11" is being bottom-adjusted in your example.  This is easier
to see if you add the following command to your example ...

	axis(1, 13, "one\ntwo")

... does the following example let you do what you want?

	plot(1:33, axes=F)
	par(mgp=c(3, 2, 0))
	axis(1, at=c(seq(0, 30, 5), 8, 12),
	     labels=c(paste(seq(0, 30, 5), "\n"), "8\n", "\n12"))

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