Hi Jim, Thank you! Your color code does work. I still do not understand how red to yellow in RGB space translates to cs1=c(1,1),cs2=(c(0,1),cs3=0. In other words, I have RGB values for red and yellow. How do I go from there to the code you sent? Another question: some of my matrices have missing cells and I do not want to assign any colors to the missing cells. The following code gives me error. I am trying to use the output (cellcol) to the function color2D.matplot.> cellcol<-matrix("#000000", nrow=nrow(plotdata),ncol=ncol(plotdata)) > cellcol[x<0.33]<-color.scale(x[x<0.33],c(1,0.8),c(0,0.8),0, na.color=NA)Error in cellcol[x < 0.33] <- color.scale(x[x < 0.33], c(1, 0.8), c(0, : NAs are not allowed in subscripted assignments In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf ? Postdoctoral Associate Department of Biology University of Maryland, College Park On Fri, Oct 9, 2015 at 7:24 AM, Jim Lemon <drjimlemon at gmail.com> wrote:> Hi Kumar, > The color.scale function translates numeric values into one or more > intervals of color by a linear transformation into the numeric values that > specify colors. One of three color spaces (rgb, hcl and hsv) can be > specified, and the endpoints can be specified as "extremes=c(<minimum > color>,<maximum color>" or as three vectors of numbers. By default, the RGB > color space is used, so: > > # starts at RGB #FF0000 and finishes at RGB #FFFF00 > red to yellow - extremes=c("red","yellow") OR cs1=c(1,1),cs2=(c(0,1),cs3=0 > # starts at RGB #FFFF00 and finishes at RGB #00FF00 > yellow to green - extremes=c("yellow","green") OR > cs1=c(1,0),cs2=(c(1,1),cs3=0 > > Obviously the shades of colors that you want may differ from the above, so > you have to play with the values to get the ones you want. In many cases, > you will have to specify more than two numbers for the color specs to get > the "in between" colors right, especially if the span of the colors is > large. > > Jim > > On Fri, Oct 9, 2015 at 4:15 PM, Kumar Mainali <kpmainali at gmail.com> wrote: > >> Hi Jim and others: >> >> I needed color code for some color gradients in color.scale function. I >> found that the following translates to green to yellow to >> red: c(0,1,1),c(1,1,0),0. How does this string translate to the color >> gradient? I would like to know the gradient code for red to yellow, yellow >> to green and other ranges. >> >> Thanks, >> Kumar Mainali >> >> Postdoctoral Associate >> Department of Biology >> University of Maryland, College Park >> > >[[alternative HTML version deleted]]
Hi Kumar, You're overthinking it: in RGB, colorspace, cs1 is red, cs2 is green, cs3 is blue. So if cs1=c(1,1),cs2=(c(0,1),cs3=0 (or c(0,0) because of R's recycling) the first color in the sequence is c(1, 0, 0) or red ##FF0000 and the second color is c(1, 1, 0) #FFFF00 or yellow. Sarah On Fri, Oct 9, 2015 at 11:16 AM, Kumar Mainali <kpmainali at gmail.com> wrote:> Hi Jim, > > Thank you! Your color code does work. I still do not understand how red to > yellow in RGB space translates to cs1=c(1,1),cs2=(c(0,1),cs3=0. In other > words, I have RGB values for red and yellow. How do I go from there to the > code you sent? > > Another question: some of my matrices have missing cells and I do not want > to assign any colors to the missing cells. The following code gives me > error. I am trying to use the output (cellcol) to the > function color2D.matplot. > >> cellcol<-matrix("#000000", nrow=nrow(plotdata),ncol=ncol(plotdata)) >> cellcol[x<0.33]<-color.scale(x[x<0.33],c(1,0.8),c(0,0.8),0, na.color=NA) > Error in cellcol[x < 0.33] <- color.scale(x[x < 0.33], c(1, 0.8), c(0, : > NAs are not allowed in subscripted assignments > In addition: Warning messages: > 1: In min(x) : no non-missing arguments to min; returning Inf > 2: In max(x) : no non-missing arguments to max; returning -Inf > ? > > Postdoctoral Associate > Department of Biology > University of Maryland, College Park > > On Fri, Oct 9, 2015 at 7:24 AM, Jim Lemon <drjimlemon at gmail.com> wrote: > >> Hi Kumar, >> The color.scale function translates numeric values into one or more >> intervals of color by a linear transformation into the numeric values that >> specify colors. One of three color spaces (rgb, hcl and hsv) can be >> specified, and the endpoints can be specified as "extremes=c(<minimum >> color>,<maximum color>" or as three vectors of numbers. By default, the RGB >> color space is used, so: >> >> # starts at RGB #FF0000 and finishes at RGB #FFFF00 >> red to yellow - extremes=c("red","yellow") OR cs1=c(1,1),cs2=(c(0,1),cs3=0 >> # starts at RGB #FFFF00 and finishes at RGB #00FF00 >> yellow to green - extremes=c("yellow","green") OR >> cs1=c(1,0),cs2=(c(1,1),cs3=0 >> >> Obviously the shades of colors that you want may differ from the above, so >> you have to play with the values to get the ones you want. In many cases, >> you will have to specify more than two numbers for the color specs to get >> the "in between" colors right, especially if the span of the colors is >> large. >> >> Jim >> >> On Fri, Oct 9, 2015 at 4:15 PM, Kumar Mainali <kpmainali at gmail.com> wrote: >> >>> Hi Jim and others: >>> >>> I needed color code for some color gradients in color.scale function. I >>> found that the following translates to green to yellow to >>> red: c(0,1,1),c(1,1,0),0. How does this string translate to the color >>> gradient? I would like to know the gradient code for red to yellow, yellow >>> to green and other ranges. >>> >>> Thanks, >>> Kumar Mainali >>>
Hi Sarah, Thanks for the explanation. This solves my first problem. I hope somebody will be able to answer my second question. Copied here from previous email>>Another question: some of my matrices have missing cells and I do not want to assign any colors to the missing cells. The following code gives me error. I am trying to use the output (cellcol) to the function color2D.matplot.> cellcol<-matrix("#000000", nrow=nrow(plotdata),ncol=ncol(plotdata)) > cellcol[x<0.33]<-color.scale(x[x<0.33],c(1,0.8),c(0,0.8),0, na.color=NA)Error in cellcol[x < 0.33] <- color.scale(x[x < 0.33], c(1, 0.8), c(0, : NAs are not allowed in subscripted assignments In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf ? Postdoctoral Associate Department of Biology University of Maryland, College Park On Fri, Oct 9, 2015 at 11:48 AM, Sarah Goslee <sarah.goslee at gmail.com> wrote:> Hi Kumar, > > You're overthinking it: > > in RGB, colorspace, cs1 is red, cs2 is green, cs3 is blue. > So if cs1=c(1,1),cs2=(c(0,1),cs3=0 (or c(0,0) because of R's recycling) > the first color in the sequence is c(1, 0, 0) or red ##FF0000 and the > second color is c(1, 1, 0) #FFFF00 or yellow. > > Sarah > > On Fri, Oct 9, 2015 at 11:16 AM, Kumar Mainali <kpmainali at gmail.com> > wrote: > > Hi Jim, > > > > Thank you! Your color code does work. I still do not understand how red > to > > yellow in RGB space translates to cs1=c(1,1),cs2=(c(0,1),cs3=0. In other > > words, I have RGB values for red and yellow. How do I go from there to > the > > code you sent? > > > > Another question: some of my matrices have missing cells and I do not > want > > to assign any colors to the missing cells. The following code gives me > > error. I am trying to use the output (cellcol) to the > > function color2D.matplot. > > > >> cellcol<-matrix("#000000", nrow=nrow(plotdata),ncol=ncol(plotdata)) > >> cellcol[x<0.33]<-color.scale(x[x<0.33],c(1,0.8),c(0,0.8),0, na.color=NA) > > Error in cellcol[x < 0.33] <- color.scale(x[x < 0.33], c(1, 0.8), c(0, : > > NAs are not allowed in subscripted assignments > > In addition: Warning messages: > > 1: In min(x) : no non-missing arguments to min; returning Inf > > 2: In max(x) : no non-missing arguments to max; returning -Inf > > ? > > > > Postdoctoral Associate > > Department of Biology > > University of Maryland, College Park > > > > On Fri, Oct 9, 2015 at 7:24 AM, Jim Lemon <drjimlemon at gmail.com> wrote: > > > >> Hi Kumar, > >> The color.scale function translates numeric values into one or more > >> intervals of color by a linear transformation into the numeric values > that > >> specify colors. One of three color spaces (rgb, hcl and hsv) can be > >> specified, and the endpoints can be specified as "extremes=c(<minimum > >> color>,<maximum color>" or as three vectors of numbers. By default, the > RGB > >> color space is used, so: > >> > >> # starts at RGB #FF0000 and finishes at RGB #FFFF00 > >> red to yellow - extremes=c("red","yellow") OR > cs1=c(1,1),cs2=(c(0,1),cs3=0 > >> # starts at RGB #FFFF00 and finishes at RGB #00FF00 > >> yellow to green - extremes=c("yellow","green") OR > >> cs1=c(1,0),cs2=(c(1,1),cs3=0 > >> > >> Obviously the shades of colors that you want may differ from the above, > so > >> you have to play with the values to get the ones you want. In many > cases, > >> you will have to specify more than two numbers for the color specs to > get > >> the "in between" colors right, especially if the span of the colors is > >> large. > >> > >> Jim > >> > >> On Fri, Oct 9, 2015 at 4:15 PM, Kumar Mainali <kpmainali at gmail.com> > wrote: > >> > >>> Hi Jim and others: > >>> > >>> I needed color code for some color gradients in color.scale function. I > >>> found that the following translates to green to yellow to > >>> red: c(0,1,1),c(1,1,0),0. How does this string translate to the color > >>> gradient? I would like to know the gradient code for red to yellow, > yellow > >>> to green and other ranges. > >>> > >>> Thanks, > >>> Kumar Mainali > >>> >[[alternative HTML version deleted]]