Skip to content
Back to formatted view

Raw Message

Message-ID: <CAEQKoCHc+51r6T1aBQw8o57Mh9fqcww_uHf04PpHjLtB6Wf8Yg@mail.gmail.com>
Date: 2015-05-24T12:51:33Z
From: Brian Smith
Subject: plot: rug colors
In-Reply-To: <5561BF6F.5060206@gmail.com>

Thanks Duncan! That works!

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

> On 24/05/2015 7:47 AM, Brian Smith wrote:
> > 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?
>
> 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
>

	[[alternative HTML version deleted]]