beginner
beginner

Reputation: 1069

How to make a color bar using three columns?

I have a table like following:

ID    type  group
A3EP    1    M
A3MA    2    M
A459    3    M
A3I1    5    M
A9D2    7    M
A3M9    4    M
A7XP    6    M
A4ZP    8    M

I want to make a color bar like following: Red color represents "group" and below that each color represents "type" and below that I want the "ID" names.

enter image description here

Can anyone please tell me how to do this? Thank you.

Upvotes: 0

Views: 100

Answers (1)

Adam Quek
Adam Quek

Reputation: 7153

mypalette <- rainbow(8)
barplot(rep(0.5,8), width=1, space=0, col=mypalette, axes=F)
text(df$type-.5, .2, df$ID,  srt=90)

rect(0, .4, 8, .5, col="red")
text(4, .45, "M")

enter image description here

Input data:

df <- structure(list(ID = structure(c(1L, 4L, 5L, 2L, 8L, 3L, 7L, 6L
), .Label = c("A3EP", "A3I1", "A3M9", "A3MA", "A459", "A4ZP", 
"A7XP", "A9D2"), class = "factor"), type = 1:8, group = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L), class = "factor", .Label = "M")), .Names = 
c("ID", 
"type", "group"), row.names = c(NA, -8L), class = "data.frame")

Upvotes: 2

Related Questions