Thanks your helping.
• 0 views
•
link
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'
Your sample (first) columns has no name, and it should be named Sample_id for your code to work.
Thanks your helping.
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. 
Log in to answer this question.
You need to post what
pca.scoreslooks like. You're also missing a geometry to add to the plot, likegeom_point().sorry about that. I have posted a part of the code.