Of course, here is a fully contained example (data is fetched from Github Gist):
library(dplyr)
library(lattice)
# Function to compute jitter
meanJitterByClass <- function(d, c) {
z <- filter(d, Class==c)
jitter <- c()
for (r in 1:nrow(z)) {
jitter <- c(jitter, d$NWCRT[r] - d$NBCRT[r])
}
return (mean(jitter))
}
# Data presentation mode
# Major groups (columns) are things like your Utilisation, or Chain Length
# Minor groups have a row label, like "Class" being "0", "1", or "2"
# Prior to reshape, we're going to format our data as follows:
# VALUES (i.e jitter) | GROUP (i.e. Total) | Subgroup (i.e. mode)
raw <- read.csv(url("https://gist.githubusercontent.com/Micrified/cd3c00bbf8429e5701f0af31b54ed109/raw/c01e7a0a35dc6bceb7b14d6ed38df8210256a7c9/data.csv"))
raw <- as.data.frame(raw)
colnames(raw) <- c("ID", "Utilisation", "Class", "NWCRT", "NBCRT", "NACRT", "Seed", "Total")
df <- NULL
# For each Group (major) (The group column is called "Total" in the data, and has possible values [0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90])
for (i in 1:9) {
# Create three Subgroups (minor) (The subgroup column is called "Mode" and has possible values [1, 2, 3])
subset <- filter(raw, Total==(i*0.10))
rbind(df, c(meanJitterByClass(subset, "0"), i, 0)) -> df
rbind(df, c(meanJitterByClass(subset, "1"), i, 1)) -> df
rbind(df, c(meanJitterByClass(subset, "2"), i, 2)) -> df
}
# Not elegant? Also, has NA inside?
# We can modify our data for a base barplot using reshape (??)
# base <- reshape()