Tuesday, September 9, 2014

9 9 2014 Distribution Overlay Graphs in R for Size Data

DistributionOverlayGraphs.R
library(ggplot2)
#ggplot2 makes the distribution curve graphs
library(car)
#not sure what car does but I think it works with lattices
library(splitstackshape)
## Loading required package: data.table
#splitstackshape is an easy package that can help you split columns that have delimiters,
#Original CSV file column labelled "Tray" had entries that needed to be split
picsize5=read.csv('ImageJsize4.csv')
#creates dataframe and reads in the CSV file for sizes
picsize6<-concat.split.multiple(picsize5, "Tray", " ")
#splits the Tray column into Tray_1 with Site Number and Tray_2 with Tray number
foys<-subset(picsize6, Date=="2/26/2014"& Site=="Oyster Bay")
#creates a subset data frame for just the size data from February 26th at Oyster Bay
ggplot(foys, aes(x=Length.mm))+geom_density(aes(group=Tray_1, colour=Tray_1, fill=Tray_1),alpha=0.3)
plot of chunk unnamed-chunk-1
#creates distribution graph overlays for all populations in Feb at Oyster Bay. Looks cool.
fman<-subset(picsize6, Date=="2/26/2014"& Site=="Manchester")
ggplot(fman, aes(x=Length.mm))+geom_density(aes(group=Tray_1, colour=Tray_1, fill=Tray_1),alpha=0.3)
plot of chunk unnamed-chunk-1
ffid<-subset(picsize6, Date=="2/28/2014"&Site=="Fidalgo")
ggplot(ffid, aes(x=Length.mm))+geom_density(aes(group=Tray_1, colour=Tray_1, fill=Tray_1),alpha=0.3)
plot of chunk unnamed-chunk-1
#ffid and fman are just repeating the same subset dataframe command
#and then creating distribution overlay graphs for each site

No comments:

Post a Comment