Last active
January 25, 2018 16:20
-
-
Save eliocamp/ab6bec917ea4bc0940a554fc40f9bc7f to your computer and use it in GitHub Desktop.
Relief Shade in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(data.table) | |
library(ggplot2) | |
data(volcano) | |
volcano <- as.data.table(melt(volcano, varnames = c("x", "y"), | |
value.name = "h")) | |
volcano[, c("dx", "dy") := metR::Derivate(h ~ x + y)] # from my package. It calculates directional derivatives. | |
volcano[, angle := atan2(-dy, -dx)] | |
sun.angle <- pi/3 | |
ggplot(volcano, aes(x, y)) + | |
geom_raster(aes(fill = cos(angle + sun.angle)), alpha = 1, interpolate = TRUE) + | |
scale_fill_gradient2(low = "white", high = "white", mid = "gray20", | |
midpoint = sun.angle, guide = "none") + | |
coord_fixed() + | |
theme_void() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment