tr = read.csv("seg exp2-table.csv", skip = 6) # read in netlogo csv file, skip 6 info lines at start # select fields interested in - note R has transformed their names to remove illegal charaters ts <- data.frame(density = tr$density, threshold = tr$X..similar.wanted, segregation = tr$percent.similar) # calaculate averages for each unique (density, threshold) pair ta <- aggregate(ts, by=list(ts$density,ts$threshold), FUN=mean) # print details of what has been created print ("created: tr <- csv file, ts <- selected renamed columns, ta <- averages") # plot a chart based on data in ta library(lattice) quartz("seg-exp2", 4.5, 4) # open a display window for chart fsize <- 1.25 # font size to use in plot p <- levelplot (segregation ~ threshold * density, data = ta, main = list("segregation (percent-similar)",cex=fsize), # title xlab = list("threshold (%-similar-wanted)", cex=fsize), # x-axis label ylab = list("density", cex=fsize), # y-axis label scales=list(cex=fsize), #size of x,y scales font colorkey = list(labels=list(cex=fsize)), #size of ledgend font at=seq(50,100,by=5), # segregation level thresholds to use #set colors for thresholds col.regions = colorRampPalette(c("white", "yellow", "orange", "red", "purple", "black")), region = TRUE ) print (p) # display the plot