Skip to content

Instantly share code, notes, and snippets.

@ajdamico
Created December 7, 2014 19:00
Show Gist options
  • Save ajdamico/6ec0e696af72a6fda22a to your computer and use it in GitHub Desktop.
Save ajdamico/6ec0e696af72a6fda22a to your computer and use it in GitHub Desktop.
world without water
# setwd( "C:/My Directory/wwow/" )
path.to.7z <- normalizePath( "C:/Program Files (x86)/7-zip/7z.exe" )
library(stringr)
library(downloader)
library(raster)
library(rasterVis)
source_url(
"https://raw.github.com/ajdamico/usgsd/master/Download%20Cache/download%20cache.R" ,
prompt = FALSE ,
echo = FALSE
)
tf <- tempfile()
download.cache( "http://www.ngdc.noaa.gov/mgg/global/relief/ETOPO1/data/bedrock/grid_registered/netcdf/ETOPO1_Bed_g_gdal.grd.gz" , tf )
# unzip the file
shell( paste0( '"' , path.to.7z , '" x ' , tf ) )
r <- raster( 'ETOPO1_Bed_g_gdal.grd' )
m <- mean( values( r ) )
your.length <- 25
# 1/4th of a centimeter per layer
# 4 layers per centimeter x 25 layers in total =
# 6.25 centimeters for the entire depth
# 6.25 centimeters = 2.46 inches deep.
values( r ) <- findInterval( values( r ) , seq( m - 5000 , m + 5000 , length = your.length ) )
for ( i in seq( your.length , 1 ) ){
p <-
gplot( r ) + geom_tile( aes( fill = value ) ) + scale_fill_gradient( limits = c( 0 , i ) , na.value = 'white' ) +
# blank out the legend and axis labels
theme(
legend.position = "none" ,
axis.title.x = element_blank() ,
axis.title.y = element_blank()
) +
# blank out other plot elements
scale_x_continuous( limits = c( -180 , 180 ) , breaks = NULL ) +
scale_y_continuous( limits = c( -90 , 90 ) , breaks = NULL ) +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
panel.border = element_blank(),
axis.ticks = element_blank()
)
ggsave( plot = p , filename = paste0( 'wwow' , str_pad( i , 2 , pad = '0' ) , '.pdf' ) , width = 20 , height = 10 )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment