Change color text axis in barplot

I'm trying to print barplot with custom color x axis, following code is what I'm doing, but its doesn't work.

# Samples subsetting
Col_T <- rownames(Res$Coldata[Res$Coldata$condition == "Colon_Transverse",])
Col_S <- rownames(Res$Coldata[Res$Coldata$condition == "Colon_Sigmoid",])
Stom <- rownames(Res$Coldata[Res$Coldata$condition == "Stomach",])
Intes <- rownames(Res$Coldata[Res$Coldata$condition == "Small_Intestine_Terminal_Ileum",])


a <- ifelse(A1$V2 %in% Col_T , "orange",
            ifelse(A1$V2 %in% Col_S, "red",
                   ifelse(A1$V2 %in% Stom, "blue","green")))

barplot(A1[,1], names.arg = A1[,2], las=2, cex.names=0.2, col.axis = as.data.frame(a))

A1 dataframe

"structure(list(ENSG00000111701.6 = c(0.236339539168374, 0.837216667053029, "               
 [2] "0.980390956061472, 0.570560078936309, 1.04404433270602, 1.38072944850355, "                
 [3] "1.08338358771008, 1.40053792958373, 1.90881290773955, 0.125849442065685, "                 
 [4] "2.05588975819628, 2.51172103270762, 0.813853003582868, 1.449957483628, "                   
 [5] "2.82497146545623), V2 = c(\"GTEX-14C39-1926-SM-5ZZW5\", \"GTEX-1128S-1626-SM-5H12O\", "    
 [6] "\"GTEX-14ICK-1026-SM-6AJA4\", \"GTEX-17F98-1026-SM-7IGO8\", \"GTEX-ZY6K-1226-SM-5GZYL\", " 
 [7] "\"GTEX-VJYA-2026-SM-4KL1K\", \"GTEX-ZP4G-1726-SM-4WWCM\", \"GTEX-PX3G-1426-SM-48U1J\", "   
 [8] "\"GTEX-SE5C-1526-SM-4BRWU\", \"GTEX-WH7G-1326-SM-4LVMS\", \"GTEX-1AYCT-1826-SM-731EG\", "  
 [9] "\"GTEX-QMRM-1226-SM-447C6\", \"GTEX-S4P3-1226-SM-4AD4Y\", \"GTEX-XQ8I-2126-SM-4BOOM\", "   
[10] "\"GTEX-ZPCL-1826-SM-57WF1\")), row.names = c(\"GTEX-14C39-1926-SM-5ZZW5\", "               
[11] "\"GTEX-1128S-1626-SM-5H12O\", \"GTEX-14ICK-1026-SM-6AJA4\", \"GTEX-17F98-1026-SM-7IGO8\", "
[12] "\"GTEX-ZY6K-1226-SM-5GZYL\", \"GTEX-VJYA-2026-SM-4KL1K\", \"GTEX-ZP4G-1726-SM-4WWCM\", "   
[13] "\"GTEX-PX3G-1426-SM-48U1J\", \"GTEX-SE5C-1526-SM-4BRWU\", \"GTEX-WH7G-1326-SM-4LVMS\", "   
[14] "\"GTEX-1AYCT-1826-SM-731EG\", \"GTEX-QMRM-1226-SM-447C6\", \"GTEX-S4P3-1226-SM-4AD4Y\", "  
[15] "\"GTEX-XQ8I-2126-SM-4BOOM\", \"GTEX-ZPCL-1826-SM-57WF1\"), class = \"data.frame\")"  

Col_T :

[1] "c(\"GTEX-111CU-1426-SM-5GZYP\", \"GTEX-111VG-2226-SM-5N9DU\", \"GTEX-111YS-1626-SM-5GZZ9\", "
[2] "\"GTEX-1122O-1526-SM-5N9CL\", \"GTEX-1128S-1626-SM-5H12O\", \"GTEX-117YW-1826-SM-5PNY5\", "  
[3] "\"GTEX-117YX-0826-SM-5H11J\", \"GTEX-11DXX-1826-SM-5H126\", \"GTEX-11DXZ-1726-SM-5H12M\", "  
[4] "\"GTEX-11EM3-1526-SM-5A5KN\", \"GTEX-11EQ9-1426-SM-5987G\", \"GTEX-11GSP-1626-SM-5986N\", "  
[5] "\"GTEX-11I78-1226-SM-5A5K6\", \"GTEX-11LCK-2026-SM-5A5MA\", \"GTEX-11NSD-1626-SM-5986U\""    
[6] ")"

Col_S:

[1] "c(\"GTEX-111CU-1226-SM-5EGIN\", \"GTEX-111YS-1826-SM-5GIEP\", \"GTEX-1122O-1426-SM-5H11R\", "
[2] "\"GTEX-117XS-2226-SM-5GIE1\", \"GTEX-117YX-0526-SM-5EGJH\", \"GTEX-11DXX-1926-SM-5EGJK\", "  
[3] "\"GTEX-11DXY-2026-SM-5N9CZ\", \"GTEX-11DXZ-1626-SM-5GIDI\", \"GTEX-11EI6-2626-SM-5PNVT\", "  
[4] "\"GTEX-11EM3-1626-SM-5N9CO\", \"GTEX-11EMC-1426-SM-5N9E4\", \"GTEX-11EQ9-1526-SM-5PNY7\", "  
[5] "\"GTEX-11GS4-1826-SM-5HL4T\", \"GTEX-11I78-1326-SM-5PNY9\", \"GTEX-11ONC-1926-SM-5GU75\""    
[6] ")"

Stom:

[1] "c(\"GTEX-111CU-0926-SM-5EGIK\", \"GTEX-111YS-1126-SM-5GZYQ\", \"GTEX-1122O-1926-SM-5EGIQ\", "
[2] "\"GTEX-117YW-2226-SM-5N9DB\", \"GTEX-117YX-1026-SM-5H11V\", \"GTEX-11DXX-1326-SM-5GIDZ\", "  
[3] "\"GTEX-11EI6-2426-SM-5PNVS\", \"GTEX-11EM3-1026-SM-5A5KL\", \"GTEX-11EQ9-1226-SM-5987E\", "  
[4] "\"GTEX-11GSP-2126-SM-5HL5E\", \"GTEX-11I78-1726-SM-5A5M3\", \"GTEX-11NSD-1426-SM-5HL67\", "  
[5] "\"GTEX-11NUK-2426-SM-5BC4U\", \"GTEX-11P7K-1726-SM-5GU6F\", \"GTEX-11P82-0726-SM-5PNYL\""    
[6] ")"

Intes:

[1] "c(\"GTEX-111CU-1326-SM-5NQ8L\", \"GTEX-111YS-1426-SM-5GID8\", \"GTEX-1122O-1326-SM-5H11F\", "
[2] "\"GTEX-117YX-0326-SM-5GICL\", \"GTEX-1192X-2526-SM-59868\", \"GTEX-11DXX-1626-SM-5H11H\", "  
[3] "\"GTEX-11DXZ-1326-SM-5H11X\", \"GTEX-11EQ9-1326-SM-5985X\", \"GTEX-11I78-1126-SM-5A5K5\", "  
[4] "\"GTEX-11LCK-1926-SM-5A5KE\", \"GTEX-11NSD-1726-SM-5N9C3\", \"GTEX-11P7K-1626-SM-5GU63\", "  
[5] "\"GTEX-11P82-0826-SM-5P9GU\", \"GTEX-11VI4-1626-SM-5EQKO\", \"GTEX-11XUK-1426-SM-5EQMG\""    
[6] ")" 

Thank you in andvance

Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

Currently, without access to the dataset behind your code, it is difficult to help you. Thanks.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.