How to label by colour in PCA plot?
0
0
Entering edit mode
23 months ago
Info.shi ▴ 30

Hi everyone.

I plot PCA using below command.

data1 <- data[,apply(data, 2, function(x) all(x > 0))]

pca.result <- prcomp(data1,center = TRUE, scale. = TRUE)

autoplot(pca.result, label=TRUE)

I want to label all .Non in one color and .Acc in one color.

I tried using ggplot but in that case which file I should retrieve is problem.

Kindly please me code to label the color using autoplot.

Thank you.

enter image description here

label PCA plot. colure • 1.6k views
ADD COMMENT
0
Entering edit mode

You need to hand both the pca.result, and data1 with a column of the identifiers to the plot function. So if your column of .Non and .Acc is called "type", you would say:

autoplot(pca.result, data = data1, colour = 'type')

The cran docs for how to plot pca might help.

ADD REPLY
0
Entering edit mode

Thank you but I want different color for all .Non (Red) and .Non (Blue).

But this autoplot(pca.result, data = data1, colour = 'type') convert all in one colour.

That would be great if you can suggest me more.

Thank you.

ADD REPLY
0
Entering edit mode

If it's giving them all the same color, then they must all have the same label in the 'type' column. Can you provide a few rows of your data? Here's an example of a few rows of data that would get unique colors for each point type, because there are distinct labels for each type:

       C1     C2     C3     C4 type
g1  0.360  1.490  0.505 -0.800  Non
g2  1.270  0.939 -0.438  0.194  Non
g3 -0.179 -1.320 -0.963  1.400  Acc
g4  0.221  0.303 -0.464 -0.484  Acc
g5 -1.010  1.590 -0.576  0.689  Non

What does your label column look like?

ADD REPLY
0
Entering edit mode

Thank you so much.

My matrix file look like as follows.

enter image description here

ADD REPLY
0
Entering edit mode

That's the PCA result. What we need to see is the first few lines of the input data matrix: data1. If the data1 matrix has the same values as in the "Replicate" column of the PCA result, then each dot will get a different color, because each line has a unique value (1.Acc, 2.Acc). If you want to classify them, as Acc or Nom, you night have to create a column for just those values. Ether way, showing the first few lines of data1 would be informative.

ADD REPLY

Login before adding your answer.

Traffic: 2562 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6