Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- setwd("C:/Users/vschoe11/Dropbox/Projects/Timberlake/plates/060916")
- plates<-read.csv("Data for plates csv.csv", header=T)
- plates1.5<-plates[which(plates$Depth==1.5),]
- data.loess <- loess(range ~ Distance * UseMonth2, data = plates1.5)
- ygrid <- seq(min(0), max(1.9), 0.01)
- xgrid <- seq(min(1), max(5), 0.1)
- data.fit <- expand.grid(Distance = ygrid, UseMonth2 = xgrid)
- mtrx3d <- predict(data.loess, newdata = data.fit)
- contour(x = xgrid, y = ygrid, z = mtrx3d, xlab = "UseMonth2", ylab = "Distance")
- library(reshape2)
- mtrx.melt <- melt(mtrx3d, id.vars = c("Distance", "UseMonth2"), measure.vars = "range")
- names(mtrx.melt) <- c("Distance", "UseMonth2", "range")
- library(stringr)
- mtrx.melt$Distance <- as.numeric(str_sub(mtrx.melt$Distance, str_locate(mtrx.melt$Distance, "=")[1,1] + 1))
- mtrx.melt$UseMonth2 <- as.numeric(str_sub(mtrx.melt$UseMonth2, str_locate(mtrx.melt$UseMonth2, "=")[1,1] + 1))
- library(ggplot2)
- labels_mon <- c("June", "July", "August", "Sept", "Oct")
- plotrange <- ggplot(mtrx.melt, aes(y = Distance, x = as.Date(UseMonth2, origin="2012-06-01"), z = range)) +
- theme_bw()+
- theme(axis.title=element_text(size=12))+
- stat_contour(geom = "polygon", aes(fill = ..level..))+
- geom_tile(aes(fill = range)) +
- stat_contour(bins=20, color="black")+
- xlab("Month") +
- ylab("Distance") +
- guides(fill = guide_colorbar(title = "range"))+
- scale_fill_gradientn(colours = c("blue", "yellow", "red"))+
- theme(legend.position="bottom")
- plotrange
Add Comment
Please, Sign In to add comment