Skip to content

Instantly share code, notes, and snippets.

@dwinter
Last active August 29, 2015 14:14
Show Gist options
  • Save dwinter/09dd32e9ac338e32ae43 to your computer and use it in GitHub Desktop.
Save dwinter/09dd32e9ac338e32ae43 to your computer and use it in GitHub Desktop.
multiple plots, each with there own scale_gradient()
library(ggplot2)
library(grid)
make_normal_cont <- function(Ea, n=100, steps=11){
Ut <- 0.2/Ea
x <- rma_normal(n, Ea, Ea/10, 1e-4, Ut)
effect_sizes <- seq(1e-4, Ea * 2, length.out=steps)
mus <- seq(Ut - Ut/1.2, Ut *3, length.out=steps)
res <- expand.grid(mean_effect = effect_sizes, Ut=mus)
res$Lik <- apply(res, 1, function(r) dma_normal(x, a=r[1], Va =r[1]/50,
1e-4, r[2], log=TRUE))
# res$Lik <- exp(res$Lik)
p <- ggplot(res, aes(Ut, mean_effect, fill=Lik, z=Lik))
p + geom_raster() + scale_fill_gradient() + geom_contour(colour='white') +
geom_point(x=Ut, y=Ea, colour="white", size=2)
}
grid_layout <- list( c(1,1),
c(1,2),
c(2,1),
c(2,2))
Ea <- c(0.01, 0.02, 0.04, 0.1)
set.seed(321123)
grid.newpage()
pushViewport(viewport(layout=grid.layout(2,2)))
for(i in 1:4){
p <- make_normal_cont(Ea[i], 1000, 31)
print(p, vp=viewport(layout.pos.row=grid_layout[[i]][1],
layout.pos.col=grid_layout[[i]][2]))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment