0

I am running some PC analysis with the geomorph package on r and am trying to understand how to group my specimens. My specimens are grouped by weeks (week 1, week 5 and week 10) and I am trying to confirm that my code is indeed correct and grouping my specimens correctly. I used various coding tips from the cran file and another quick guide to geomorph.

Essentially what I did was create a csv file where each specimen has a number that corresponds to their order in the TPS file and what week they come from. My PC plots appear to be correct but I wanted to confirm that R is indeed reading my csv file correctly. I am relatively new to R so I would love some confirmation or a suggestion of some better code to be sure that week 1's points are indeed representative of week 1 specimens. I have attached a photo snip of my csv file for a sense of what that looks like (new to stack overflow and not sure what the best way to display this) Example CSV. Any input would be much appreciated, either to confirm that my code is correct or to suggest a better way to code for a grouping variable with tps files and geomorph.

setwd("/Users/tritz/Desktop/Analysis")
GP <- read.csv("W1w5w10.csv", header=T, row.names=1)
is.factor(GP$Week)
lands <- readland.tps(file.choose())
#My tps file is standard tps file, with specimen number corresponding to 
#their order in this file 
gpa.lands <-gpagen(lands)
View(gpa.lands)
plotAllSpecimens(lands)
gpagen(lands)
pca.lands <- plotTangentSpace(gpa.lands$coords, legend=TRUE, groups = 
GP$Week)
View(pca.lands)

POST EDIT : Specific code I am asking question about

GP <- read.csv("W1w5w10.csv", header=T, row.names=1)
is.factor(GP$Week)
#This code links my csv file and I am unsure if it is reading correctly
pca.lands <- plotTangentSpace(gpa.lands$coords, legend=TRUE, groups = 
GP$Week)
#here is where I generated my PC plot and linked my groups with the week 
#factor in my csv
tritz18
  • 1
  • 1
  • Welcome to SO! You have a lot of code going on here, thank you for providing all of the background. Please be more precise about which aspect of this you need guidance with, it's unclear at the moment what you are asking. I suggest posting the specific sections of code that you want people to look at. – EcologyTom Jul 27 '18 at 13:09
  • See post edit, I am just trying to figure out if my csv file is getting read correctly based on how it is set up in the attached image and if my code is correctly picking out week 1 specimens as week 1 and so on for week 5 and week 10 – tritz18 Jul 27 '18 at 13:45
  • Ok. There's no reason to think that it hasn't been read "correctly". I think you are concerned that the week order is incorrect? Have a look at `str(GP$Week)`, this will tell you your factor order. If you want them in a different order then look at the help files for `level`. It is not possible to tell exactly what's going on without some test data, next time please include some sample data (have a look at other questions here on SO to get ideas of how to do this). – EcologyTom Jul 27 '18 at 14:23
  • I couldn't figure out how to attach a tps file to this question, that is why I didn't provide more data. I was just unsure how my code was identifying specimen1 (with associated location info on csv file) to my first specimen and its coordinates on my tps file. Based on my PC plots that I just ran with a large group sample size vs a small group sample size it is working based on how many dots are being plotted and identified by group. So I guess that confirms it is identifying the right grouping variable. – tritz18 Jul 27 '18 at 15:10

0 Answers0