Question: (Closed) How to color subset of row ?
0
gravatar for Björn
8 months ago by
Björn40
Björn40 wrote:

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 • 203 views
ADD COMMENTlink modified 8 months ago by zx87547.3k • written 8 months ago by Björn40

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!

ADD REPLYlink modified 8 months ago • written 8 months ago by ATpoint16k

found the answer

color<-c("red","darkolivegreen", "brown4","darkgoldenrod3", "deeppink2","bisque"[6:44])
color[is.na(color)]<-"bisque"
ADD REPLYlink modified 8 months ago • written 8 months ago by Björn40

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"
ADD REPLYlink written 8 months ago by zx87547.3k

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!

ADD REPLYlink written 8 months ago by Alex Reynolds28k
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: 1784 users visited in the last hour