This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to color subset of row ?

For example, I have a column

x<-c(a, b, c, D, E, F, G, H,I..........X,Y,Z)

How can I create a color parameter such that

a = red
b= green
c= blue

and rest of UPPERCASE into one specific color e.g. "black"

r

Hello Björn!

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

This is an R, rather than a bioinformatics question. In line with your previous questions, you do not show any efford in putting together an elaborate question. For the future, please motivate people by posting what you've tried so far to avoid being considered lazy.

As for your problem, you simply have to find the positions of the pattern in the array, e.g. using grep or match, and then make a new array where this position is the name of the color. Google will help you digging into commands like grep and match. For the uppercase ones, google for 'R check if uppercase'.

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!

found the answer

color<-c("red","darkolivegreen", "brown4","darkgoldenrod3", "deeppink2","bisque"[6:44])
color[is.na(color)]<-"bisque"

Try switch function instead, example:

#example data
x <- c("a","b","c","D","E","F","G","H","I","X","Y","Z")

# use switch to assign colours
sapply(x, switch,
       a = "red",
       b = "green",
       c = "blue",
       "black", USE.NAMES = FALSE)
# [1] "red"   "green" "blue"  "black" "black" "black" "black" "black" "black" "black" "black" "black"

Hello Björn!

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

This is not a bioinformatics question. You might ask on Stack Overflow.

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!

0 answers

No answers yet.

Log in to answer this question.