Automated image point-count to ordination

This is a draft bit of code to allows the user to take .csv files that commonly come from image analysis programs, combine them together into a data.frame in R, wrangle the rows and columns into the required format for ordination analysis. This code will also allow for csv files with uneven columns.

Note: This code is in beta testing. Make sure to check your data at each step to make sure it all makes sense.

Capture2
A Photoquad screenshot
  1.  This is a typical csv with taxa in column C

Capture1

2. Have all your csv’s in a seperate folder

3.  The first chunck of code imports all the csv data into a tibble in R

library(dplyr)
library(readr)
df <- list.files(full.names = TRUE) %>%
lapply(read_csv) %>%
bind_rows
head(df)

4. The second chunk groups the tibble by image and flips to wide format. Cells created by mashing everything together give NA. These can be set to zero as no count was made for that taxa.

df2
library(tidyverse)
df3 = df2 %>% group_by(Image) %>% pivot_wider(names_from = ‘spp Name’, values_from = ‘Cov% per species’, names_prefix = “area”) #year goes to columns, #their areas go as the values, area is the prefix
df3
df3[is.na(df3)] <- 0 #all NA to zero
names(df3)
tail(df3)

5. A basic nMDS from the data

# library(tidyverse)
df4 = subset(df3, select=-Image)
library(vegan)
comMDS2 <- metaMDS(df4, distance = “bray”, autotransform = T) #20 random #interactions
library(ggordiplots)
ggordi <- gg_ordiplot(comMDS2, groups = df3$Image, plot = T) ##

You are probably wondering how to automate the image analysis part. There are quite a few people working on this but also comes with a huge amount of challenges for images high in complexity and diversity. Laboratory (wet -lab ) experimental images are much easier and I will add a post on how to do this at some stage.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s