I am new to ggplot2, and I am trying to replicate a graph that I created using filled.contour
with ggplot2.
below is my code:
require(gg
To create a ggplot
version of the filled.contour
plot you'll need to have a larger data.frame
than the df
object in your example and using geom_tile
will produce the plot you are looking for. Consider the following:
# a larger data set
scl <- 10
dat <- expand.grid(x = scl * seq(0, 1, by = 0.01),
y = scl * seq(0, 1, by = 0.01))
dat$z <- ((scl - dat$x) * dat$y) / ((scl - dat$x) * dat$y + 1)
# create the plot, the geom_contour may not be needed, but I find it helpful
ggplot(dat) +
aes(x = x, y = y, z = z, fill = z) +
geom_tile() +
geom_contour(color = "white", alpha = 0.5) +
scale_fill_gradient(low = "lightblue", high = "magenta") +
theme_bw()