Question: (Closed) Output the color code according to number
0
gravatar for 2012201024
3.8 years ago by
201220102420
China
201220102420 wrote:

Hi,

I want to get a series of color code, like #0000FF, according to a list of number. I can set a color scale in R heatmap and draw a picture, but how to get the code list of color?  Hope somebody help.

Thanks!

R • 1.3k views
ADD COMMENTlink modified 3.8 years ago • written 3.8 years ago by 201220102420

Many thanks for your reply.

Furthermor, if I input a list like "1  3.5   4.5  9   2", and want to output the corresponding color code, according to a scale, how should I operate? 

ADD REPLYlink written 3.8 years ago by 201220102420

Hi- If you have a string like "1  3.5   4.5  9   2", then you have to split it and convert to numeric:

x<- "1  3.5   4.5  9   2"
xn<- as.numeric(strsplit(x, ' ')[[1]])
xn<- xn[!is.na(xn)] # Remove NAs

Then use xn as above for listOfNum.

(By the way, for clarifications like this use the "add comment" feature instead of posting it as an answer).

 

ADD REPLYlink written 3.8 years ago by dariober9.4k

Hello 2012201024!

We believe that this post does not fit the main topic of this site.

This is not a Bioinformatics question.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

ADD REPLYlink modified 3.8 years ago • written 3.8 years ago by Sukhdeep Singh9.4k

OK, Thank you for your advice.

In fact, I'm using graphlan to draw a metagenome picture, because the software don't provid color code of heatmap, so I should get them through this method.

Sorry about that.

ADD REPLYlink written 3.8 years ago by 201220102420
5
gravatar for dariober
3.8 years ago by
dariober9.4k
Glasgow - UK
dariober9.4k wrote:

Not sure I fully understand your question but let's see if this helps:

listOfNum<- 1:5
colour<- colorRampPalette(c("blue", "red"))(length(listOfNum))
colour
[1] "#0000FF" "#3F00BF" "#7F007F" "#BF003F" "#FF0000"
plot(listOfNum, col= colour, pch= 19, cex= 3)

ADD COMMENTlink modified 3.8 years ago • written 3.8 years ago by dariober9.4k
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1939 users visited in the last hour