Re: [R] X-Axis Label Overwritten By TickMark Values

From: Marc Schwartz <MSchwartz_at_mn.rr.com>
Date: Sun 02 Oct 2005 - 01:23:55 EST

On Sat, 2005-10-01 at 06:07 -0500, Paul Roebuck wrote:
> Can someone tell me how to fix the left margin of plot region
> such that the tick values don't overwrite the x-axis label?
> I haven't been able to set the correct par option to fix this...
>
> TIA
>
> ------------
> grdev <- function(...) {
> get(getOption("device"))(...)
> }
>
> plotFixMe <- function(spectrum, ...) {
> saved.par <- par(las = 1, tcl = 0.3)
> on.exit(par(saved.par))
>
> plot(spectrum,
> type = "l",
> col = "blue",
> xlab = "",
> ylab = "",
> ...)
> title(main = "x-axis label overwritten by tick values",
> xlab = "Index",
> ylab = "Intensity")
> }
>
> grdev()
> plotFixMe(rnorm(50)*20000, ylim = c(0, 50000))

Paul,

This is the Y axis label, not the X axis.

Set par("mar") prior to creating the plot to increase the left hand margin space and then use mtext() rather than title() to move the Y axis label further left by using the 'line' argument.

grdev <- function(...) {

    get(getOption("device"))(...)
}

plotFixMe <- function(spectrum, ...) {

    saved.par <- par(las = 1, tcl = 0.3)     on.exit(par(saved.par))

    par(mar = c(5, 6, 4, 2))

    plot(spectrum,

         type = "l",
         col  = "blue",
         xlab = "",
         ylab = "",
         ...)

    title(main = "x-axis label overwritten by tick values")

    mtext(1, text = "Index", line = 3)
    mtext(2, text = "Intensity", line = 5, las = 3) }

grdev()
plotFixMe(rnorm(50)*20000, ylim = c(0, 50000))

See ?par and ?mtext for more information.

BTW, I would not use 'tcl = 0.3' which, as a positive value, places the tick marks themselves within the plot region. That's contrary to typical guidance, since the tick marks get lost in this plot and more importantly, can overwrite data points in certain plot types.

HTH, Marc Schwartz



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Oct 02 01:34:17 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:34 EST