Guest User

Untitled

a guest
Nov 16th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. filenames <- list.files(path=".",
  2. pattern="csv",
  3. full.names=TRUE)
  4. pdfnames <- paste(substr(filenames, 1, nchar(filenames)-4),".pdf",sep="")
  5. pdfmaster <- paste(substr(filenames,1,15),".pdf",sep="")
  6.  
  7. # List of variables being displayed
  8. variable = c("Dimensionless potential temperature",
  9. "Melt fraction",
  10. "Melting rate",
  11. ...)
  12.  
  13. #Creates a contour plot in ggplot of the variable in xz space
  14. makeplot <- function(filename) {
  15. xx <- which(filenames==filename)
  16. data <- as.data.frame(read.csv(file=filename), header = FALSE)
  17. ggplot(data=data, mapping = aes(x = data[,2],
  18. y=data[,1],
  19. z = data[,3])) +
  20.  
  21. geom_raster(data=data, aes(fill=data[,3]), show.legend=TRUE, interpolate
  22. = FALSE) +
  23. scale_fill_gradient(limits=range(data[,3]), high = 'red', low = 'white') +
  24. geom_contour(bins = 30, colour = "black") +
  25. xlab(label = "Distance from ridge axis") +
  26. ylab(label = "Depth") +
  27. theme_bw()+
  28. coord_cartesian(
  29. ylim = c(0,1), xlim = c(0,2))+
  30. scale_x_continuous(expand = c(0, 0)) +
  31. scale_y_continuous(expand = c(0, 0)) +
  32. guides(fill=guide_legend(title=variable[xx]),
  33. guide_colorbar(title=NULL))
  34.  
  35. }
  36.  
  37. # Making one pdf file per plot
  38. for (f in 1:length(filenames)) {
  39. pdf(file=pdfnames[f], height=3, width=6)
  40. print(makeplot(filenames[f]))
  41. dev.off()
  42. }
  43.  
  44. # Making all plots in one pdf
  45. pdf(file=pdfmaster[1], height=6, width=12)
  46. for (f in 1:length(filenames)) {
  47. print(makeplot(filenames[f]))
  48. }
  49. dev.off()
Add Comment
Please, Sign In to add comment