An question about PCA analysis of protein data in R
1
0
Entering edit mode
10 months ago
741801556 • 0

I wonder know how to define the fill and colour using my data in R?

Code is as follows:

data <- read.table("G:/protomtics/20231228-QCM-Gas/20231229-QCM-Gas/data analysis/pca_data.csv",header = T, row.names = 1, sep = ",")
pca <- principal(train.scale, rotate="none")
plot(pca$values, type="b", ylab="Eigenvalues", xlab="Component")
pca.rotate <- principal(train.scale, nfactors = 2, rotate ="varimax")
pca.rotate

pca.scores <- data.frame(pca.rotate$scores)
head(pca.scores)

                 RC1         RC2
WT_1_126    56.09007  54.1052753
WT_2_127    64.48834  48.1215063
WT_3_126    64.96041   0.5308317
WT_4_127    71.08494  -4.6388461
DMD_1_128N -70.23270 -32.4267293
DMD_2_128C -68.77648 -42.3431540#

pca.scores$Sample_id <- data$Sample_id
library(ggplot2)

p1<-ggplot(pca.scores, aes(x = RC1, y = RC2,fill = Sample_id,colour = Sample_id)
Caused by error:
! Can't find a date.'Sample_id'
PCA • 736 views
ADD COMMENT
0
Entering edit mode

You need to post what pca.scores looks like. You're also missing a geometry to add to the plot, like geom_point().

ADD REPLY
0
Entering edit mode

sorry about that. I have posted a part of the code.

ADD REPLY
0
Entering edit mode
10 months ago
Mensur Dlakic ★ 28k

Your sample (first) columns has no name, and it should be named Sample_id for your code to work.

ADD COMMENT
0
Entering edit mode

Thanks your helping.

ADD REPLY
0
Entering edit mode

If an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one answer if they all work. If an answer was not really helpful or did not work, provide detailed feedback so others know not to use that answer.
upvote_bookmark_accept

ADD REPLY

Login before adding your answer.

Traffic: 1995 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