Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
DataExploration-AAPF/display_variance.r
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
97 lines (69 sloc)
2.94 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(ggplot2) | |
# Path to input and output data | |
path.rgb.long <- ("./df_rgb_long.csv") | |
path.hsi.long <- ("./df_hsi_long.csv") | |
path.rpt <- ("./rpt_no_public.csv") | |
# Variables demonstrating highest to n-th highest repeatability will be displayed | |
# in each combination of (TREATMENT, GROWTH_STAGE) | |
n <- 5 | |
# List of varieties to be excluded, if any; otherwise, exclude.variety as "c()" | |
exclude.variety <-c("P1", "P2", "P3", "P4") | |
# Load RGB and HSI data in long format | |
message("Loading data...") | |
df.rgb <- read.csv(path.rgb.long) | |
df.hsi <- read.csv(path.hsi.long) | |
df.rpt <- read.csv(path.rpt) | |
# Exclude varieties, as needed | |
if (length(exclude.variety)>0){ | |
df.rgb <- df.rgb %>% filter(!VARIETY %in% exclude.variety) | |
df.hsi <- df.hsi %>% filter(!VARIETY %in% exclude.variety) | |
} | |
# Combine RGB and HSI data | |
df <- rbind(df.rgb, df.hsi) | |
# Simplify attributes under df.rpt$View | |
df.rpt$View <- replace(df.rpt$View, | |
df.rpt$View %in% c("SideAll", "SideAverage"), | |
"Side") | |
df$View <- replace(df$View, | |
df$View %in% c("SideAll", "SideAverage"), | |
"Side") | |
# Choose valid repeatability measurements | |
df.rpt <- df.rpt[!is.na(df.rpt$rpt),] | |
for (treatment in unique(df.rpt$TREATMENT)){ | |
for (growth.stage in unique(df.rpt$GROWTH_STAGE)){ | |
print(paste0("Generating plots for ", | |
treatment, ", ", growth.stage, " case...")) | |
# Subset data by treatment and growth stage | |
df.rpt.temp <- df.rpt[which(df.rpt$TREATMENT==treatment & | |
df.rpt$GROWTH_STAGE==growth.stage), ] | |
df.rpt.temp <- df.rpt.temp[order(df.rpt.temp$rpt, decreasing=T), ] | |
for (i in seq(1, n)){ | |
# Gather measurements from a variable with n-th highest repeatability | |
row <- df.rpt.temp[i,] | |
df.temp <- df[which(df$TREATMENT==row$TREATMENT & | |
df$GROWTH_STAGE==row$GROWTH_STAGE & | |
df$View==row$View & | |
df$frame_nr==row$frame_nr & | |
df$variable==row$variable), ] | |
# Draw box plot | |
p = ggplot(df.temp, aes(x=VARIETY, y=value)) + | |
ggtitle(paste0("Repeatability=", round(row$rpt, 3))) + | |
geom_boxplot() + | |
ylab(paste("Variable: ", | |
row$TREATMENT, row$GROWTH_STAGE, | |
row$View, row$frame_nr, row$variable, | |
sep='_')) | |
path.plot <- paste0(paste('./variance', | |
row$TREATMENT, row$GROWTH_STAGE, | |
i, | |
row$View, row$frame_nr, row$variable, | |
sep='_'), '.png') | |
# Save plot | |
png(path.plot) | |
print(p) | |
dev.off() | |
} | |
} | |
} | |
# EOF |