library(rremat) library(ggplot2) library(scales) library(knitr) opts_chunk$set(fig.width = 12, fig.height = 8, echo = FALSE)
data(ctd) baseplot = function(p) ggplot(p, aes(x = depth, color = id)) + scale_x_reverse() + coord_flip() + scale_y_continuous(breaks = pretty_breaks()) + facet_wrap(~ dist, nrow = 1) lyrs = list( ta = geom_line(aes(y = ta)), sa = geom_line(aes(y = sa)), fl = geom_line(aes(y = fl)), oa = geom_line(aes(y = oa)), sat = geom_line(aes(y = sat)), da = geom_line(aes(y = fl)), bt = geom_line(aes(y = bt)) ) dates = unique(ctd$date) names(dates) = paste(dates) ctd.plots = vector("list", length = length(lyrs)) names(ctd.plots) = names(lyrs) for(n in names(ctd.plots)){ ctd.plots[[n]] = vector("list", length = length(dates)) names(ctd.plots[[n]]) = paste(dates) for(d in names(dates)) ctd.plots[[n]][[d]] = baseplot(subset(ctd, date == dates[[d]])) + lyrs[[n]] + ggtitle(d) }
for(p in ctd.plots$ta) print(p)
for(p in ctd.plots$sa){ print(p) }
for(p in ctd.plots$oa) print(p)
data(grids) baseplot = function(p) ggplot(p, aes(x = dist, y = elev)) + xlim(min(grids$dist), max(grids$dist)) + ylim(min(grids$elev), max(grids$elev)) + facet_wrap(~ id) lyrs = list( ta = geom_raster(aes(fill = ta)), sa = geom_raster(aes(fill = sa)), fl = geom_raster(aes(fill = fl)), oa = geom_raster(aes(fill = oa)), sat = geom_raster(aes(fill = sat)), da = geom_raster(aes(fill = fl)), bt = geom_raster(aes(fill = bt)) ) dates = unique(grids$date) names(dates) = paste(dates) grids.plots = vector("list", length = length(lyrs)) names(grids.plots) = names(lyrs) for(n in names(grids.plots)){ grids.plots[[n]] = vector("list", length = length(dates)) names(grids.plots[[n]]) = paste(dates) for(d in names(dates)) grids.plots[[n]][[d]] = baseplot(na.omit(subset(grids, date== dates[[d]]))) + lyrs[[n]] + ggtitle(d) }
for(p in grids.plots$ta) print(p + scale_fill_gradientn(colours = rev(c("#A50026", "#D73027", "#F46D43", "#FDAE61", "#FEE090", "#E0F3F8", "#ABD9E9", "#74ADD1", "#4575B4", "#313695"))))
for(p in grids.plots$sa) print(p + scale_fill_gradientn(colours = rev(c("#A50026", "#D73027", "#F46D43", "#FDAE61", "#FEE090", "#E0F3F8", "#ABD9E9", "#74ADD1", "#4575B4", "#313695"))) )
for(p in grids.plots$oa) print(p + scale_fill_gradientn(colours = c("#A50026", "#D73027", "#F46D43", "#FDAE61", "#FEE090", "#E0F3F8", "#ABD9E9", "#74ADD1", "#4575B4", "#313695")) )
data(wll)
ggplot(wll, aes(x = mtime, y = depth)) + geom_line() + facet_wrap(~ site, ncol = 1)
ggplot(wll, aes(x = mtime, y = temp)) + geom_line() + facet_wrap(~ site, ncol = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.