Guest User

Untitled

a guest
Oct 20th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. setwd("C:/Users/vschoe11/Dropbox/Projects/Timberlake/plates/060916")
  2. plates<-read.csv("Data for plates csv.csv", header=T)
  3.  
  4. plates1.5<-plates[which(plates$Depth==1.5),]
  5.  
  6. data.loess <- loess(range ~ Distance * UseMonth2, data = plates1.5)
  7. ygrid <- seq(min(0), max(1.9), 0.01)
  8. xgrid <- seq(min(1), max(5), 0.1)
  9. data.fit <- expand.grid(Distance = ygrid, UseMonth2 = xgrid)
  10. mtrx3d <- predict(data.loess, newdata = data.fit)
  11. contour(x = xgrid, y = ygrid, z = mtrx3d, xlab = "UseMonth2", ylab = "Distance")
  12. library(reshape2)
  13. mtrx.melt <- melt(mtrx3d, id.vars = c("Distance", "UseMonth2"), measure.vars = "range")
  14. names(mtrx.melt) <- c("Distance", "UseMonth2", "range")
  15. library(stringr)
  16. mtrx.melt$Distance <- as.numeric(str_sub(mtrx.melt$Distance, str_locate(mtrx.melt$Distance, "=")[1,1] + 1))
  17. mtrx.melt$UseMonth2 <- as.numeric(str_sub(mtrx.melt$UseMonth2, str_locate(mtrx.melt$UseMonth2, "=")[1,1] + 1))
  18. library(ggplot2)
  19. labels_mon <- c("June", "July", "August", "Sept", "Oct")
  20. plotrange <- ggplot(mtrx.melt, aes(y = Distance, x = as.Date(UseMonth2, origin="2012-06-01"), z = range)) +
  21. theme_bw()+
  22. theme(axis.title=element_text(size=12))+
  23. stat_contour(geom = "polygon", aes(fill = ..level..))+
  24. geom_tile(aes(fill = range)) +
  25. stat_contour(bins=20, color="black")+
  26. xlab("Month") +
  27. ylab("Distance") +
  28. guides(fill = guide_colorbar(title = "range"))+
  29. scale_fill_gradientn(colours = c("blue", "yellow", "red"))+
  30. theme(legend.position="bottom")
  31. plotrange
Add Comment
Please, Sign In to add comment