Inconsistent color of group points on PCA plots

24 views
Skip to first unread message

Claudia

unread,
Jul 25, 2025, 5:46:55 PMJul 25
to geomorph R package
Hi, everyone - I'm having an issue with defining the color of each group on PCA plots.  

Using the plot() function after performing PCA, my group colors are selected from the default R palette.  When I re-plot the colors of each group using custom defined colors, however, not all of the points in each group are consistently converted into the new group color.  In my specific case, the points that were black in the first PC plot are not all converted to yellow in the second PC plot, and the points that were pink in the first PC plot are not all converted to green in the second PC plot.  Some of the points that were black or pink were, respectively, converted into green or yellow points.  I'm not sure why this is the case.  Why aren't the group colors staying consistent after choosing what colors I want to use?  Is there a way to define colors/a color palette that won't do this?

I've attached the relevant files needed to see my problem - your help is greatly appreciated!

Best,
Claudia
mastoid.txt
MASTOID.R
classifier_mastoid.csv
curvslide_mastoid.csv

Claudia

unread,
Jul 25, 2025, 5:51:35 PMJul 25
to geomorph R package
My apologies - please use the following .R file (instead of MASTOID.R).

Thank you!
Astorino_R_script_7.25.25.R

Adams, Dean [EEOB]

unread,
Jul 26, 2025, 3:48:18 PMJul 26
to geomorph R package
Claudia,

Pch = 19 is a solid black circle. You cannot change the background or the outline color of this option.

As for the colors you designated manually, your correct plot is not correct. Since you provided it only 2 values, R will cycle through those for your large number of specimens.  Try designating a color vector, perhaps something like this:

col.gp[which(SEX_gps =='F')] <- "#F2AD00"
col.gp[which(SEX_gps =='M')] <- "#00A08A"

plot(PCA, 
     pch = 22, 
     cex = 1.5, 
     bg = col.gp

Dean
--
Dr. Dean C. Adams
Distinguished Professor
Director, Ecology and Evolutionary Biology Graduate Program
Department of Ecology, Evolution, and Organismal Biology
Iowa State University

From: 'Claudia' via geomorph R package <geomorph-...@googlegroups.com>
Sent: Friday, July 25, 2025 4:51 PM
To: geomorph R package <geomorph-...@googlegroups.com>
Subject: [geomorph-r-package] Re: Inconsistent color of group points on PCA plots
 
--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/geomorph-r-package/e1580813-438c-4520-9a77-f0c4f3890b83n%40googlegroups.com.
Message has been deleted
Message has been deleted
Message has been deleted

Adams, Dean [EEOB]

unread,
Jul 30, 2025, 5:36:19 PMJul 30
to geomorph R package
Claudia,

My apologies. There was a line of code that got omitted in my email response. Try this:

col.gp <- as.vector(SEX_gps)
col.gp[which(SEX_gps =='F')] <- "#F2AD00"
col.gp[which(SEX_gps =='M')] <- "#00A08A"

plot(PCA, 
     pch = 22, 
     cex = 1.5, 
     bg = col.gp

Incidentally, these are not issues specific to the geomorph package, but instead with an understanding of writing code in base-R.  While I am happy to assist with the former, I suggest that to gain more proficiency in the R language, you read up via some basic (and freely available) books and resources on how to manage, manipulate, and otherwise program in R.

Best,

Dean
--
Dr. Dean C. Adams
Distinguished Professor
Director, Ecology and Evolutionary Biology Graduate Program
Department of Ecology, Evolution, and Organismal Biology
Iowa State University

From: 'Adams, Dean [EEOB]' via geomorph R package <geomorph-...@googlegroups.com>
Sent: Saturday, July 26, 2025 2:48 PM

To: geomorph R package <geomorph-...@googlegroups.com>
Subject: Re: [geomorph-r-package] Re: Inconsistent color of group points on PCA plots
 
Reply all
Reply to author
Forward
0 new messages