Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- filenames <- list.files(path=".",
- pattern="csv",
- full.names=TRUE)
- pdfnames <- paste(substr(filenames, 1, nchar(filenames)-4),".pdf",sep="")
- pdfmaster <- paste(substr(filenames,1,15),".pdf",sep="")
- # List of variables being displayed
- variable = c("Dimensionless potential temperature",
- "Melt fraction",
- "Melting rate",
- ...)
- #Creates a contour plot in ggplot of the variable in xz space
- makeplot <- function(filename) {
- xx <- which(filenames==filename)
- data <- as.data.frame(read.csv(file=filename), header = FALSE)
- ggplot(data=data, mapping = aes(x = data[,2],
- y=data[,1],
- z = data[,3])) +
- geom_raster(data=data, aes(fill=data[,3]), show.legend=TRUE, interpolate
- = FALSE) +
- scale_fill_gradient(limits=range(data[,3]), high = 'red', low = 'white') +
- geom_contour(bins = 30, colour = "black") +
- xlab(label = "Distance from ridge axis") +
- ylab(label = "Depth") +
- theme_bw()+
- coord_cartesian(
- ylim = c(0,1), xlim = c(0,2))+
- scale_x_continuous(expand = c(0, 0)) +
- scale_y_continuous(expand = c(0, 0)) +
- guides(fill=guide_legend(title=variable[xx]),
- guide_colorbar(title=NULL))
- }
- # Making one pdf file per plot
- for (f in 1:length(filenames)) {
- pdf(file=pdfnames[f], height=3, width=6)
- print(makeplot(filenames[f]))
- dev.off()
- }
- # Making all plots in one pdf
- pdf(file=pdfmaster[1], height=6, width=12)
- for (f in 1:length(filenames)) {
- print(makeplot(filenames[f]))
- }
- dev.off()
Add Comment
Please, Sign In to add comment