Dirk Eddelbuettel
2003-Aug-06 21:30 UTC
[R] Plot ticks and tick labels: thickness, colour?
I am displaying several series in one plot, and would like to make them distinct without having to employ a legend. I managed to color tickmarks, but have been unsuccessful with either one of a) making tickmarks thicker (without increasing the axis at the same time). From reading ?axis: lty, lwd: line type, width for the axis line and the tick marks. in would appear that I cannot obtain the one _without_ the other; or b) displaying the tick label in a different colour. Again, ?axis reads col: color for the axis line and the tick marks. [..] indicates that I can only set the tick mark, not the annotation. Any ideas or suggestions? Thanks in advance, Dirk -- Those are my principles, and if you don't like them... well, I have others. -- Groucho Marx
On Wed, 2003-08-06 at 16:30, Dirk Eddelbuettel wrote:> I am displaying several series in one plot, and would like to make > them distinct without having to employ a legend. > > I managed to color tickmarks, but have been unsuccessful with either one of > > a) making tickmarks thicker (without increasing the axis at the same time). > From reading ?axis: > lty, lwd: line type, width for the axis line and the tick marks. > in would appear that I cannot obtain the one _without_ the other; or > > b) displaying the tick label in a different colour. Again, ?axis reads > col: color for the axis line and the tick marks. [..] > indicates that I can only set the tick mark, not the annotation. > > Any ideas or suggestions? > > Thanks in advance, DirkDirk, One possible option: # Generic plot with no tick marks or annotation plot(1:10, 1:10, axes = FALSE, ann = FALSE) # First get par("usr") to get x and y axis ranges usr <- par("usr") # Now draw tick marks, using axTicks() to get # default locations # First, x axis at.x <- axTicks(1) segments(at.x, usr[3], at.x, usr[3] - ((usr[4] - usr[3]) * 0.01), lwd = 2, col = "red", xpd = TRUE) # Draw x axis tick mark labels mtext(at.x, at = at.x, side = 1, line = 1, col = "red") # Now do the same for the y axis at.y <- axTicks(2) segments(usr[1], at.y, usr[1] - ((usr[2] - usr[1]) * 0.01), at.y, lwd = 2, col = "blue", xpd = TRUE) # Draw y axis tick mark labels mtext(at.y, at = at.y, side = 2, line = 1, col = "blue") # put a box around the plot region box() In the above calls to segments(), adjust the '* 0.01' to be the tick mark length you wish as a proportion of the axis range and of course the 'lwd' and 'col' to your preference. If you want the tick marks inside the plot region, rather than outside, change the initial subtractions to additions. Note the use of 'xpd TRUE', so that the tick marks are not clipped at the plot region for 'outside'. If you need to use something other than the default tick mark locations, you can always adjust 'at.x' and 'at.y' to whatever you choose. HTH, Marc Schwartz
Thomas W Blackwell
2003-Aug-06 22:56 UTC
[R] Plot ticks and tick labels: thickness, colour?
Dirk - You can certainly make tickmarks thinner than the axis line by multiple calls to axis() with different values for lwd. MAYBE you can overwrite an earlier call by setting col.axis="white" (and no tickmarks) but I've never tried this. mtext() allows building custom tick labels. In R-1.7.1, help("axis") seems to disagree with help("par") on whether the arguments to axis() are called "col" and "font" (as in help(axis)) or "col.axis", "col.lab" and "font.lab" (as in help(par)). In my experience, help(par) rules. But, do you REALLY want to get into this ! - tom blackwell - u michigan medical school - ann arbor - On Wed, 6 Aug 2003, Dirk Eddelbuettel wrote:> I am displaying several series in one plot, and would like to make > them distinct without having to employ a legend. > > I managed to color tickmarks, but have been unsuccessful with either one of > > a) making tickmarks thicker (without increasing the axis at the same time). > From reading ?axis: > lty, lwd: line type, width for the axis line and the tick marks. > in would appear that I cannot obtain the one _without_ the other; or > > b) displaying the tick label in a different colour. Again, ?axis reads > col: color for the axis line and the tick marks. [..] > indicates that I can only set the tick mark, not the annotation. > > Thanks in advance, Dirk