Skip to content

plot: rug colors

3 messages · Duncan Murdoch, Brian Smith

#
Hi,

I wanted the rug (in plot) to have different colors. For example:

vals1 <- sample(1:100,5)
vals2 <- sample(1:100,5)

rugcols <- c("red","blue","brown","red","yellow")

plot(vals1,vals2)
rug(vals1,col=rugcols,lwd=2)


However, with this code I only get 'red' for all the ticks. Is there a way
I can get the different colors for rug?

thanks!
#
On 24/05/2015 7:47 AM, Brian Smith wrote:
The rug() function is basically a wrapper for axis(), and it doesn't
support multiple colours of tick marks.  So what you could do is call
rug() once for each colour:

# This line is not needed in your example, but might be in general...
rugcols <- rep(rugcols, length.out=length(vals1))

for (col in unique(rugcols)) {
  show <- rugcols == col
  rug(vals1[show], col=col, lwd=2)
}

Duncan Murdoch
#
Thanks Duncan! That works!

On Sun, May 24, 2015 at 8:09 AM, Duncan Murdoch <murdoch.duncan at gmail.com>
wrote: