knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

gplatesr is an R package contaning example code showing how to use the GPlates web service to get plate reconstructions directly from http requests. GPlates is developed by the EarthByte Group [https://www.earthbyte.org]

Installation

First, install gplatesr into your computer. Soon you'll be able to install the stable version of the package from cran

install.packages("gplatesr")

or you can install the development version from github

devtools::install_github("LunaSare/gplatesr")

Now load the package into the R workspace.

library(gplatesr)

Reconstructing plates at any point in time

First load some necessary libraries for graph generation

library(ggplot2)
library(ggthemes)
library(sp)

Now set the time of reconstruction (we choose 140 Mya for this example) and get the coordinates of coastlines and plates:

recon_time <- 140
dat <- gplates_reconstruct_coastlines(recon_time)
dat2 <- gplates_reconstruct_static_polygons(recon_time)
dat3 <- gplates_plate_polygons(recon_time)

Now prepare the coordinates data to generate the graph:

dat_map <- fortify(dat)
dat2_map <- fortify(dat2)
dat3_map <- fortify(dat3)
outline <- bbox(dat)
outline <- data.frame(xmin=-180,xmax=180,ymin=-90,ymax=90)
gg <- ggplot()
gg <- gg + geom_map(data=dat2_map, map=dat2_map,
                    aes(x=long, y=lat, map_id=id),
                    color="white", size=0.15, fill="#d8d8d6")
gg <- gg + geom_map(data=dat_map, map=dat_map,
                    aes(x=long, y=lat, map_id=id),
                    color="white", size=0.15, fill="darkkhaki")
gg <- gg + geom_map(data=dat3_map, map=dat3_map,
                    aes(x=long, y=lat, map_id=id),
                    color="red", size=0.15, fill=NA)
#gg <- gg + geom_point(aes(x=coords[1], y=coords[2]))
gg <- gg + geom_rect(data=outline,
                     aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax),
                     color=1, fill=NA, size=0.3)
gg <- gg + scale_size(name="Magnitude", trans="exp", labels=c(5:8), range=c(1, 20))
gg <- gg + coord_map("mollweide")
gg <- gg + theme_map()
gg <- gg + ggtitle(sprintf('Time = %0.1fMa', recon_time))
gg <- gg + theme(panel.border=element_blank())

Now you can print your reconstruction on screen by simpy calling the gg object

gg

Or you can save it to disk as pdf or png using:

pdf("my-reconstruction.pdf", width = 680, height = 480, units = "px", pointsize = 12)
# or
png("my-reconstruction.png", width = 680, height = 480, units = "px", pointsize = 12)
print(gg)
dev.off()
knitr::include_graphics("plate-recons-140.png", dpi = 360)


LunaSare/gplatesr documentation built on Aug. 30, 2022, 12:27 a.m.