[R] X-Axis Label Overwritten By TickMark Values
Marc Schwartz
MSchwartz at mn.rr.com
Sat Oct 1 17:23:55 CEST 2005
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
More information about the R-help
mailing list