문제

So I am new to this. I need to run PCoA on the following data matrix. I am able to run my analyses using ADE4, labdsv, Ginko, Aabel softwares. Whats bothering me is how to color code the labels in the scatter plot. My matrix is a presence/absence matrix in the order:

SpecieName Value1 Value2
A1         0      1
A2         1      1
A3         1      1
B1         0      0
B2         0      1
E1         1      0
E2         0      0

What I want is to represent A1, A2, and A3 in red, B1 and B2 in Blue and all the E ones in black. Any help will be appreciated.

도움이 되었습니까?

해결책

Just pass in a factor that denotes these groups to the plotting command:

data = read.table('data.txt', header=T)

data.pca = prcomp(data[,-1])

groups = factor(gsub('(.).', '\\1', data$SpecieName))

plot(data.pca$x, col=groups)

enter image description here

Also, if you want to set specific colors, you can always index into a custom list the same way:

cols = c('red', 'blue', 'black')[groups]
plot(data.pca$x, col=cols)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top