[R] Simple color strip

Duncan Murdoch murdoch.duncan at gmail.com
Wed Oct 19 16:49:39 CEST 2011


On 19/10/2011 10:32 AM, Brian Smith wrote:
> Hi,
>
> I was trying to get an image/pdf of a sequence of colors in the order given.
> For example:
>
> myCols<- c('#0000BF','#0000BF','#0000FF','#0000FF','#0000BF','#0000FF')
>
>
> I'd like to make a strip of colors as they appear in the order above and
> save it as a pdf file. Is there a function in the base package (or some
> other package) to do this?
>

On 19/10/2011 10:32 AM, Brian Smith wrote:
> Hi,
>
> I was trying to get an image/pdf of a sequence of colors in the order given.
> For example:
>
> myCols<- c('#0000BF','#0000BF','#0000FF','#0000FF','#0000BF','#0000FF')
>
>
> I'd like to make a strip of colors as they appear in the order above and
> save it as a pdf file. Is there a function in the base package (or some
> other package) to do this?


barplot(rep(1, 6), col=myCols, axes=FALSE)

There are other options to barplot if you want the bars horizontal, 
without spacing, etc.

Putting it in a pdf is simple:  just open the pdf() device before you 
draw, and close it afterwards.

Duncan Murdoch



More information about the R-help mailing list