[R] Axis color
Marc Schwartz
MSchwartz at medanalytics.com
Mon Sep 1 18:16:50 CEST 2003
On Mon, 2003-09-01 at 09:42, solares at unsl.edu.ar wrote:
> Hello, my question is if I have two axes in a graphics as I can put him a
> different color al axis and to the number of the scale. ? Thanks. Ruben
I am not entirely sure if you want the actual axis lines and tick marks
in different colors or simply the axis labels at the tick mark locations
in different colors or perhaps both.
So I will combine both approaches in a single example:
# Generate a simple plot
# Do not draw the axes or axis labels
plot(1:10, axes = FALSE, ann = FALSE)
# Now draw x axis in red, but do not draw the tick mark
# labels.
axis(1, labels = FALSE, col = "red")
# Now draw the labels in "blue"
# Use axTicks() to get default tick locations
at = axTicks(1)
mtext(side = 1, text = at, at = at, col = "blue", line = 1)
# Now draw x axis label
mtext(side = 1, text = "X Axis Label", line = 3)
# Now do the same for the Y axis, this time
# use 1:10 for the axis tick marks and labels
# and reverse the colors
at = 1:10
axis(2, labels = FALSE, at = at, col = "blue")
mtext(side = 2, text = at, at = at, col = "red", line = 1)
mtext(side = 2, text = "Y Axis Label", line = 3)
For more information see ?plot, ?plot.default, ?axis, ?mtext and
?axTicks.
Hope that helps,
Marc Schwartz
More information about the R-help
mailing list