Re: [R] col2rgb() function

2023-07-23 Thread Ben Bolker
  You could also adjustcolor for this approach (levels of red, green, 
blue, alpha can all be adjusted proportionally)


On 2023-07-23 5:35 p.m., David Stevens via R-help wrote:

Nick,

I've also made colors transparent by pasting the hex equivalent of, say,
0.3*256 = 76.9 to the hex color code. e.q. for black it might be
"#004d" and the 4d is 77 in hex. That way you don't need to convert
back and forth so much. If col is "#00" the transparent version is

tcol <- paste0(col,"4d")

This would work in one step on a whole palette.

David

David K Stevens, PhD, PE, Professor
Civil and Environmental Engineering
Utah Water Research Laboratory
Utah State University
8200 Old Main Hill
Logan, UT 84322-8200
david.stev...@usu.edu
(435) 797-3229 (office)

On 7/23/2023 1:00 PM, Nick Wray wrote:

Thanks That works nicely  Nick

On Sun, 23 Jul 2023 at 19:26, Ben Bolker  wrote:


 Does adjustcolor() help?

cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
  "#D55E00", "#CC79A7")
plot(0,0,xlim=c(1,8),ylim=c(0,1))
points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)
points(1:8,rep(0.75,8),col=adjustcolor(cb8, alpha.f = 0.3), pch=19,cex=2)

On 2023-07-23 2:15 p.m., Nick Wray wrote:

Hello  I have a palette vector of colour blind colours (in hexadecimal)
which I’m using for plots, but they are not see-through, and as I wanted

to

overlay some histograms I wanted to convert these colours to rgb, when

you

can set the opacity.

I have found the function col2rgb(), which works in the sense that it

gives

a vector of numbers but these don’t work directly in rgb because they are
too big.  If I divide through to make them all less than 1 I don’t get

the

corresponding colour-blind hue, but something somewhat off.

Here is the colour-blind palette in a plot:


*cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
"#D55E00", "#CC79A7")*

*plot(0,0,xlim=c(1,8),ylim=c(0,1))*

*points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)*



so if I try to convert the red dot ("#D55E00") (number 7) I get

*col2rgb("#D55E00"*

 [,1]

red213

green   94

blue 0

*points(7,0.25,col=rgb(rgb(213,94,0)),pch=19,cex=2)*

gives me an error message and although if  I divide through

*points(7,0.25,col=rgb(213/307,94/307,0),pch=19,cex=2)*

gives me a reddish dot, but not the same as in the colour-blind palette



Somewhat mystified.  Can anyone help?? Thanks Nick Wray

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide

http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] col2rgb() function

2023-07-23 Thread David Stevens via R-help
Nick,

I've also made colors transparent by pasting the hex equivalent of, say, 
0.3*256 = 76.9 to the hex color code. e.q. for black it might be 
"#004d" and the 4d is 77 in hex. That way you don't need to convert 
back and forth so much. If col is "#00" the transparent version is

tcol <- paste0(col,"4d")

This would work in one step on a whole palette.

David

David K Stevens, PhD, PE, Professor
Civil and Environmental Engineering
Utah Water Research Laboratory
Utah State University
8200 Old Main Hill
Logan, UT 84322-8200
david.stev...@usu.edu
(435) 797-3229 (office)

On 7/23/2023 1:00 PM, Nick Wray wrote:
> Thanks That works nicely  Nick
>
> On Sun, 23 Jul 2023 at 19:26, Ben Bolker  wrote:
>
>> Does adjustcolor() help?
>>
>> cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
>>  "#D55E00", "#CC79A7")
>> plot(0,0,xlim=c(1,8),ylim=c(0,1))
>> points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)
>> points(1:8,rep(0.75,8),col=adjustcolor(cb8, alpha.f = 0.3), pch=19,cex=2)
>>
>> On 2023-07-23 2:15 p.m., Nick Wray wrote:
>>> Hello  I have a palette vector of colour blind colours (in hexadecimal)
>>> which I’m using for plots, but they are not see-through, and as I wanted
>> to
>>> overlay some histograms I wanted to convert these colours to rgb, when
>> you
>>> can set the opacity.
>>>
>>> I have found the function col2rgb(), which works in the sense that it
>> gives
>>> a vector of numbers but these don’t work directly in rgb because they are
>>> too big.  If I divide through to make them all less than 1 I don’t get
>> the
>>> corresponding colour-blind hue, but something somewhat off.
>>>
>>> Here is the colour-blind palette in a plot:
>>>
>>>
>>> *cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
>>> "#D55E00", "#CC79A7")*
>>>
>>> *plot(0,0,xlim=c(1,8),ylim=c(0,1))*
>>>
>>> *points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)*
>>>
>>>
>>>
>>> so if I try to convert the red dot ("#D55E00") (number 7) I get
>>>
>>> *col2rgb("#D55E00"*
>>>
>>> [,1]
>>>
>>> red213
>>>
>>> green   94
>>>
>>> blue 0
>>>
>>> *points(7,0.25,col=rgb(rgb(213,94,0)),pch=19,cex=2)*
>>>
>>> gives me an error message and although if  I divide through
>>>
>>> *points(7,0.25,col=rgb(213/307,94/307,0),pch=19,cex=2)*
>>>
>>> gives me a reddish dot, but not the same as in the colour-blind palette
>>>
>>>
>>>
>>> Somewhat mystified.  Can anyone help?? Thanks Nick Wray
>>>
>>>[[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] col2rgb() function

2023-07-23 Thread Nick Wray
Thanks v useful to know Nick

On Sun, 23 Jul 2023 at 21:13, Achim Zeileis 
wrote:

> Just one addition which may or may not be useful: The color palette you
> use is also known as "Okabe-Ito" and it is the default set of colors in
> the palette.colors() function. This function also has an optional alpha
> argument. So if you want to generate these colors with an alpha of 0.3 you
> can also do:
>
> palette.colors(8, alpha = 0.3)
>
> or more explicitly
>
> palette.colors(8, palette = "Okabe-Ito", alpha = 0.3)
>
> On Sun, 23 Jul 2023, Nick Wray wrote:
>
> > Thanks That works nicely  Nick
> >
> > On Sun, 23 Jul 2023 at 19:26, Ben Bolker  wrote:
> >
> >>Does adjustcolor() help?
> >>
> >> cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
> >> "#D55E00", "#CC79A7")
> >> plot(0,0,xlim=c(1,8),ylim=c(0,1))
> >> points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)
> >> points(1:8,rep(0.75,8),col=adjustcolor(cb8, alpha.f = 0.3),
> pch=19,cex=2)
> >>
> >> On 2023-07-23 2:15 p.m., Nick Wray wrote:
> >>> Hello  I have a palette vector of colour blind colours (in hexadecimal)
> >>> which I’m using for plots, but they are not see-through, and as I
> wanted
> >> to
> >>> overlay some histograms I wanted to convert these colours to rgb, when
> >> you
> >>> can set the opacity.
> >>>
> >>> I have found the function col2rgb(), which works in the sense that it
> >> gives
> >>> a vector of numbers but these don’t work directly in rgb because they
> are
> >>> too big.  If I divide through to make them all less than 1 I don’t get
> >> the
> >>> corresponding colour-blind hue, but something somewhat off.
> >>>
> >>> Here is the colour-blind palette in a plot:
> >>>
> >>>
> >>> *cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442",
> "#0072B2",
> >>> "#D55E00", "#CC79A7")*
> >>>
> >>> *plot(0,0,xlim=c(1,8),ylim=c(0,1))*
> >>>
> >>> *points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)*
> >>>
> >>>
> >>>
> >>> so if I try to convert the red dot ("#D55E00") (number 7) I get
> >>>
> >>> *col2rgb("#D55E00"*
> >>>
> >>>[,1]
> >>>
> >>> red213
> >>>
> >>> green   94
> >>>
> >>> blue 0
> >>>
> >>> *points(7,0.25,col=rgb(rgb(213,94,0)),pch=19,cex=2)*
> >>>
> >>> gives me an error message and although if  I divide through
> >>>
> >>> *points(7,0.25,col=rgb(213/307,94/307,0),pch=19,cex=2)*
> >>>
> >>> gives me a reddish dot, but not the same as in the colour-blind palette
> >>>
> >>>
> >>>
> >>> Somewhat mystified.  Can anyone help?? Thanks Nick Wray
> >>>
> >>>   [[alternative HTML version deleted]]
> >>>
> >>> __
> >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >>> https://stat.ethz.ch/mailman/listinfo/r-help
> >>> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >>> and provide commented, minimal, self-contained, reproducible code.
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] col2rgb() function

2023-07-23 Thread Achim Zeileis
Just one addition which may or may not be useful: The color palette you 
use is also known as "Okabe-Ito" and it is the default set of colors in 
the palette.colors() function. This function also has an optional alpha 
argument. So if you want to generate these colors with an alpha of 0.3 you 
can also do:


palette.colors(8, alpha = 0.3)

or more explicitly

palette.colors(8, palette = "Okabe-Ito", alpha = 0.3)

On Sun, 23 Jul 2023, Nick Wray wrote:


Thanks That works nicely  Nick

On Sun, 23 Jul 2023 at 19:26, Ben Bolker  wrote:


   Does adjustcolor() help?

cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
"#D55E00", "#CC79A7")
plot(0,0,xlim=c(1,8),ylim=c(0,1))
points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)
points(1:8,rep(0.75,8),col=adjustcolor(cb8, alpha.f = 0.3), pch=19,cex=2)

On 2023-07-23 2:15 p.m., Nick Wray wrote:

Hello  I have a palette vector of colour blind colours (in hexadecimal)
which I’m using for plots, but they are not see-through, and as I wanted

to

overlay some histograms I wanted to convert these colours to rgb, when

you

can set the opacity.

I have found the function col2rgb(), which works in the sense that it

gives

a vector of numbers but these don’t work directly in rgb because they are
too big.  If I divide through to make them all less than 1 I don’t get

the

corresponding colour-blind hue, but something somewhat off.

Here is the colour-blind palette in a plot:


*cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
"#D55E00", "#CC79A7")*

*plot(0,0,xlim=c(1,8),ylim=c(0,1))*

*points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)*



so if I try to convert the red dot ("#D55E00") (number 7) I get

*col2rgb("#D55E00"*

   [,1]

red213

green   94

blue 0

*points(7,0.25,col=rgb(rgb(213,94,0)),pch=19,cex=2)*

gives me an error message and although if  I divide through

*points(7,0.25,col=rgb(213/307,94/307,0),pch=19,cex=2)*

gives me a reddish dot, but not the same as in the colour-blind palette



Somewhat mystified.  Can anyone help?? Thanks Nick Wray

  [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide

http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] col2rgb() function

2023-07-23 Thread Nick Wray
Thanks That works nicely  Nick

On Sun, 23 Jul 2023 at 19:26, Ben Bolker  wrote:

>Does adjustcolor() help?
>
> cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
> "#D55E00", "#CC79A7")
> plot(0,0,xlim=c(1,8),ylim=c(0,1))
> points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)
> points(1:8,rep(0.75,8),col=adjustcolor(cb8, alpha.f = 0.3), pch=19,cex=2)
>
> On 2023-07-23 2:15 p.m., Nick Wray wrote:
> > Hello  I have a palette vector of colour blind colours (in hexadecimal)
> > which I’m using for plots, but they are not see-through, and as I wanted
> to
> > overlay some histograms I wanted to convert these colours to rgb, when
> you
> > can set the opacity.
> >
> > I have found the function col2rgb(), which works in the sense that it
> gives
> > a vector of numbers but these don’t work directly in rgb because they are
> > too big.  If I divide through to make them all less than 1 I don’t get
> the
> > corresponding colour-blind hue, but something somewhat off.
> >
> > Here is the colour-blind palette in a plot:
> >
> >
> > *cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
> > "#D55E00", "#CC79A7")*
> >
> > *plot(0,0,xlim=c(1,8),ylim=c(0,1))*
> >
> > *points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)*
> >
> >
> >
> > so if I try to convert the red dot ("#D55E00") (number 7) I get
> >
> > *col2rgb("#D55E00"*
> >
> >[,1]
> >
> > red213
> >
> > green   94
> >
> > blue 0
> >
> > *points(7,0.25,col=rgb(rgb(213,94,0)),pch=19,cex=2)*
> >
> > gives me an error message and although if  I divide through
> >
> > *points(7,0.25,col=rgb(213/307,94/307,0),pch=19,cex=2)*
> >
> > gives me a reddish dot, but not the same as in the colour-blind palette
> >
> >
> >
> > Somewhat mystified.  Can anyone help?? Thanks Nick Wray
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] col2rgb() function

2023-07-23 Thread Duncan Murdoch

On 23/07/2023 2:15 p.m., Nick Wray wrote:

Hello  I have a palette vector of colour blind colours (in hexadecimal)
which I’m using for plots, but they are not see-through, and as I wanted to
overlay some histograms I wanted to convert these colours to rgb, when you
can set the opacity.

I have found the function col2rgb(), which works in the sense that it gives
a vector of numbers but these don’t work directly in rgb because they are
too big.  If I divide through to make them all less than 1 I don’t get the
corresponding colour-blind hue, but something somewhat off.

Here is the colour-blind palette in a plot:


*cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
"#D55E00", "#CC79A7")*

*plot(0,0,xlim=c(1,8),ylim=c(0,1))*

*points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)*



so if I try to convert the red dot ("#D55E00") (number 7) I get

*col2rgb("#D55E00"*

   [,1]

red213

green   94

blue 0

*points(7,0.25,col=rgb(rgb(213,94,0)),pch=19,cex=2)*

gives me an error message and although if  I divide through

*points(7,0.25,col=rgb(213/307,94/307,0),pch=19,cex=2)*

gives me a reddish dot, but not the same as in the colour-blind palette


Why are you dividing by 307?  You should divide by 255.

Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] col2rgb() function

2023-07-23 Thread Ben Bolker

  Does adjustcolor() help?

cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
   "#D55E00", "#CC79A7")
plot(0,0,xlim=c(1,8),ylim=c(0,1))
points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)
points(1:8,rep(0.75,8),col=adjustcolor(cb8, alpha.f = 0.3), pch=19,cex=2)

On 2023-07-23 2:15 p.m., Nick Wray wrote:

Hello  I have a palette vector of colour blind colours (in hexadecimal)
which I’m using for plots, but they are not see-through, and as I wanted to
overlay some histograms I wanted to convert these colours to rgb, when you
can set the opacity.

I have found the function col2rgb(), which works in the sense that it gives
a vector of numbers but these don’t work directly in rgb because they are
too big.  If I divide through to make them all less than 1 I don’t get the
corresponding colour-blind hue, but something somewhat off.

Here is the colour-blind palette in a plot:


*cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
"#D55E00", "#CC79A7")*

*plot(0,0,xlim=c(1,8),ylim=c(0,1))*

*points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)*



so if I try to convert the red dot ("#D55E00") (number 7) I get

*col2rgb("#D55E00"*

   [,1]

red213

green   94

blue 0

*points(7,0.25,col=rgb(rgb(213,94,0)),pch=19,cex=2)*

gives me an error message and although if  I divide through

*points(7,0.25,col=rgb(213/307,94/307,0),pch=19,cex=2)*

gives me a reddish dot, but not the same as in the colour-blind palette



Somewhat mystified.  Can anyone help?? Thanks Nick Wray

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.