diff --git a/R/profile_points.R b/R/profile_points.R index f70337a..4b9bcdd 100644 --- a/R/profile_points.R +++ b/R/profile_points.R @@ -7,8 +7,8 @@ #' @param profile.azimuth numeric. Direction of profile in degrees. #' @param profile.length units object. #' @param crs Coordinate reference system. Should be readable by [sf::st_crs()]. -#' @param return.sf logical. Should the profile points be returned as a 'sf' -#' ('TRUE', the default) object or as a data.frame. +#' @param return.sf logical. Should the profile points be returned as a `sf` +#' object (`TRUE`, the default) object or as a data.frame. #' #' @note #' Use metric values (meters, kilometers, etc) in case of a projected coordinate reference frame, and degree @@ -126,9 +126,11 @@ profile_length <- function(x, ...) { #' @title Distance Between Points -#' @description This uses the **haversine** formula (by default) to calculate the great-circle -#' distance between two points, i.e., the shortest distance over the earths -#' surface. +#' +#' @description This uses the **haversine** formula (by default) to calculate +#' the great-circle distance between two points, i.e., the shortest distance +#' over the earth's surface. +#' #' @param a lon, lat coordinate of point 1 #' @param b lon, lat coordinate of point 2 #' @param ... parameters passed to [tectonicr::dist_greatcircle()] diff --git a/R/swath.R b/R/swath.R index 900a5b8..3fdaf83 100644 --- a/R/swath.R +++ b/R/swath.R @@ -26,14 +26,12 @@ #' @author V. Haburaj #' #' @export -swathR <- function(coords, raster, k, dist, crs, method) { - message("Initializing ...") - # set default method: - if (missing(method)) { - method <- "bilinear" - } +swathR <- function(coords, raster, k, dist, crs, method = 'bilinear') { + #message("Initializing ...") + # create SpatialPoints from coords: spt <- SpatialPoints(coords, proj4string = CRS(crs)) + # get slope of baseline: m <- (ymin(spt[1]) - ymin(spt[2])) / (xmin(spt[1]) - xmin(spt[2])) # get slope of normal function: @@ -134,7 +132,7 @@ swathR <- function(coords, raster, k, dist, crs, method) { #' @importFrom dplyr c_across rowwise ungroup mutate tibble as_tibble #' @export swath_profile <- function(x) { - elevs <- c() + elevs <- numeric() center <- as.character(median(seq_along(x$data))) for (i in seq_along(x$data)) { elevs <- cbind(elevs, x$data[[i]]) diff --git a/README.Rmd b/README.Rmd index bc797f9..557698d 100644 --- a/README.Rmd +++ b/README.Rmd @@ -16,11 +16,14 @@ knitr::opts_chunk$set( # geoprofiler + [![R-CMD-check](https://github.com/tobiste/geoprofiler/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tobiste/geoprofiler/actions/workflows/R-CMD-check.yaml) + -The goal of geoprofiler is to get distances along and across user-defined -profile lines or transects. This is useful when variables depend on distances. +The goal of geoprofiler is to get distances along and across user-defined profile lines or transects. This is useful when variables depend on distances. + +![Concept](man/figures/fig.png) ## Installation @@ -41,12 +44,14 @@ library(ggplot2) ``` Import example data and transfer them into a `sf` object: + ```{r quakes} data(quakes) quakes_sf <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = "WGS84") ``` Create a profile line from two known points: + ```{r profile} profile <- data.frame(lon = c(160, -170), lat = c(-15, -30)) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") |> @@ -57,12 +62,14 @@ profile <- data.frame(lon = c(160, -170), lat = c(-15, -30)) |> > Note: You can also create a profile line by a direction via `profile_points()` Calculate the distances of all points along and across the profile line: + ```{r cooridnates} quakes_profile <- profile_coords(quakes_sf, profile = profile) |> dplyr::bind_cols(quakes_sf) ``` Finally, create your profile plot: + ```{r plot} ggplot(quakes_profile, aes(X, depth, color = mag, size = abs(Y), alpha = abs(Y))) + geom_point() + @@ -77,20 +84,16 @@ ggplot(quakes_profile, aes(X, depth, color = mag, size = abs(Y), alpha = abs(Y)) ## Documentation -The detailed documentation can be found at -https://tobiste.github.io/geoprofiler/articles/geoprofiler.html - +The detailed documentation can be found at ## Author -Tobias Stephan () +Tobias Stephan ([tstephan\@lakeheadu.ca](mailto:tstephan@lakeheadu.ca){.email}) ## Feedback, issues, and contributions -I welcome feedback, suggestions, issues, and contributions! If you have -found a bug, please file it -[here](https://github.com/tobiste/geoprofiler/issues) with minimal code to -reproduce the issue. +I welcome feedback, suggestions, issues, and contributions! If you have found a bug, please file it [here](https://github.com/tobiste/geoprofiler/issues) with minimal code to reproduce the issue. ## License + MIT License diff --git a/README.md b/README.md index 016e25f..b3499c4 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,18 @@ [![R-CMD-check](https://github.com/tobiste/geoprofiler/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tobiste/geoprofiler/actions/workflows/R-CMD-check.yaml) + The goal of geoprofiler is to get distances along and across user-defined profile lines or transects. This is useful when variables depend on distances. +
+Concept + +
+ ## Installation You can install the development version of geoprofiler from diff --git a/fig.svg b/fig.svg new file mode 100644 index 0000000..4a040e3 --- /dev/null +++ b/fig.svg @@ -0,0 +1,13349 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 35 + ° + S + 30 + ° + S + 25 + ° + S + 20 + ° + S + 15 + ° + S + 10 + ° + S + + + + + + + + + + + + + + + + 155 + ° + E + 160 + ° + E + 165 + ° + E + 170 + ° + E + 175 + ° + E + 180 + ° + 180 + ° + 175 + ° + W + 170 + ° + W + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -1750 + -1500 + -1250 + -1000 + -750 + -500 + -250 + 0 + 250 + 500 + 750 + 1000 + 1250 + + + + + + + + + + + + + + Y + + + + + + + + + + + + 0 + 250 + 500 + 750 + 1000 + 1250 + 1500 + 1750 + 2000 + 2250 + 2500 + X + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + X + Y + Longitude + Latitude + diff --git a/fig1.svg b/fig1.svg new file mode 100644 index 0000000..7bcd8f0 --- /dev/null +++ b/fig1.svg @@ -0,0 +1,1161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +35 +° +S +30 +° +S +25 +° +S +20 +° +S +15 +° +S +10 +° +S + + + + + + + + + + + + + + + +155 +° +E +160 +° +E +165 +° +E +170 +° +E +175 +° +E +180 +° +180 +° +175 +° +W +170 +° +W + +mag + + + + + + + + + + + + + + + +4.5 +5.0 +5.5 +6.0 + +depth + + + + + + + +200 +400 +600 + + diff --git a/fig2.svg b/fig2.svg new file mode 100644 index 0000000..9b5b4c4 --- /dev/null +++ b/fig2.svg @@ -0,0 +1,1178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-1750 +-1500 +-1250 +-1000 +-750 +-500 +-250 +0 +250 +500 +750 +1000 +1250 + + + + + + + + + + + + + + + + + + + + + + + + +0 +250 +500 +750 +1000 +1250 +1500 +1750 +2000 +2250 +2500 +X +Y + +mag + + + + + + + + + + + + + + + +4.5 +5.0 +5.5 +6.0 + +depth + + + + + + + +200 +400 +600 + + diff --git a/man/figures/README-plot-1.png b/man/figures/README-plot-1.png index 7854654..2c3116d 100644 Binary files a/man/figures/README-plot-1.png and b/man/figures/README-plot-1.png differ diff --git a/man/figures/fig.png b/man/figures/fig.png new file mode 100644 index 0000000..151d227 Binary files /dev/null and b/man/figures/fig.png differ diff --git a/man/figures/fig.svg b/man/figures/fig.svg new file mode 100644 index 0000000..4a040e3 --- /dev/null +++ b/man/figures/fig.svg @@ -0,0 +1,13349 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 35 + ° + S + 30 + ° + S + 25 + ° + S + 20 + ° + S + 15 + ° + S + 10 + ° + S + + + + + + + + + + + + + + + + 155 + ° + E + 160 + ° + E + 165 + ° + E + 170 + ° + E + 175 + ° + E + 180 + ° + 180 + ° + 175 + ° + W + 170 + ° + W + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -1750 + -1500 + -1250 + -1000 + -750 + -500 + -250 + 0 + 250 + 500 + 750 + 1000 + 1250 + + + + + + + + + + + + + + Y + + + + + + + + + + + + 0 + 250 + 500 + 750 + 1000 + 1250 + 1500 + 1750 + 2000 + 2250 + 2500 + X + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + X + Y + Longitude + Latitude + diff --git a/man/geoprofiler-package.Rd b/man/geoprofiler-package.Rd index 36774c5..22151c3 100644 --- a/man/geoprofiler-package.Rd +++ b/man/geoprofiler-package.Rd @@ -12,6 +12,7 @@ Measures distances along lines defined by a direction. Useful links: \itemize{ \item \url{https://tobiste.github.io/geoprofiler/} + \item Report bugs at \url{https://github.com/tobiste/geoprofiler/issues} } } diff --git a/man/point_distance.Rd b/man/point_distance.Rd index d6b6403..3e94f7e 100644 --- a/man/point_distance.Rd +++ b/man/point_distance.Rd @@ -17,9 +17,9 @@ point_distance(a, b, ...) units object giving the distance } \description{ -This uses the \strong{haversine} formula (by default) to calculate the great-circle -distance between two points, i.e., the shortest distance over the earths -surface. +This uses the \strong{haversine} formula (by default) to calculate +the great-circle distance between two points, i.e., the shortest distance +over the earth's surface. } \examples{ berlin <- c(52.517, 13.4) diff --git a/man/profile_points.Rd b/man/profile_points.Rd index fa4ca2d..d1c3e8f 100644 --- a/man/profile_points.Rd +++ b/man/profile_points.Rd @@ -21,8 +21,8 @@ profile_points( \item{crs}{Coordinate reference system. Should be readable by \code{\link[sf:st_crs]{sf::st_crs()}}.} -\item{return.sf}{logical. Should the profile points be returned as a 'sf' -('TRUE', the default) object or as a data.frame.} +\item{return.sf}{logical. Should the profile points be returned as a \code{sf} +object (\code{TRUE}, the default) object or as a data.frame.} } \value{ class depends on \code{return.sf}. diff --git a/vignettes/geoprofiler.Rmd b/vignettes/geoprofiler.Rmd index 01b8723..8a1c0d1 100644 --- a/vignettes/geoprofiler.Rmd +++ b/vignettes/geoprofiler.Rmd @@ -26,7 +26,7 @@ library(units) library(sf) library(dplyr) -theme_set(theme_classic()) +theme_set(theme_bw()) options(ggplot2.continuous.colour = "viridis") options(ggplot2.continuous.fill = "viridis") ``` @@ -40,12 +40,12 @@ data("quakes") crs <- st_crs("EPSG:3460") quakes_sf <- st_as_sf(quakes, coords = c("long", "lat"), crs = "WGS84") |> - st_transform(crs = crs) + st_transform(crs = crs) quake_map <- ggplot() + geom_sf(aes(color = depth, size = mag), data = quakes_sf) + - scale_size_binned() + - theme_classic() + scale_x_continuous(breaks = seq(-360, 360, 5)) + + scale_size_binned() quake_map ``` @@ -72,7 +72,7 @@ Combine the two points to a line and add the profile line to the map: profile_l <- profile_line(profile_pts) quake_map + - geom_sf(data = profile_l, lty = 2) + geom_sf(data = profile_l, lwd = 1) ``` @@ -110,36 +110,70 @@ quakes_profile <- profile_coords(quakes_sf, profile = profile_l) |> The resulting data-frame gives the distance along the profile (`X`) and the distance from the profile (`Y`). + + A quick way to visualize the "transformed" data can be achieved by plotting these axes against each other:: ```{r profile_map} quakes_profile |> - ggplot(aes(X / 1000, Y / 1000, color = depth)) + - geom_hline(yintercept = 0) + + # divide by 1000 for km: + mutate(X = X/1000, Y = Y / 1000) |> + + ggplot(aes(X, Y, color = depth, size = mag)) + + geom_point() + + geom_hline(yintercept = 0, lwd = 1) + + scale_size_binned() + + scale_x_continuous(breaks = seq(0, 3000, 250)) + + scale_y_continuous(breaks = seq(-3000, 3000, 250)) + + coord_fixed() +``` +In this plot the profile line is a horizontal line (`X=0`) and the start point +of the profile has the coordinates `X=0` and `Y=0`. + +### Shifting the profile line + +The location of the profile line can be easily shifted to the desired spot by +adjusting the `X` and `Y` values of the transformed data. + +For example, to shift the profile line more to the 'North', we simply subtract +the desired shift (to move it 'down', we would need to add the desired number). + +```{r shift} +quakes_profile_shifted <- quakes_profile |> + mutate( + X = X/1000, # in km + Y = (Y/1000) - 500 # in km and shifted by 500 km to the "North" + ) + + ggplot(quakes_profile_shifted, aes(X, Y, color = depth, size = mag)) + geom_point() + + geom_hline(yintercept = 0, lwd = 1) + + scale_size_binned() + scale_x_continuous(breaks = seq(0, 3000, 250)) + scale_y_continuous(breaks = seq(-3000, 3000, 250)) + coord_fixed() ``` -In this plot the profile line is a horizontal line (`X=0`). +### Filtering the data This plot helps also allows to easily make a subset of our data to avoid plotting data points that are too far away from the profile: ```{r filter} quakes_profile_filtered <- filter( - quakes_profile, - abs(Y) <= 750 * 1000, - X >= 1500 * 1000 + quakes_profile_shifted, + abs(Y) <= 750, + X >= 1600 ) ``` ## Plot data along profile + Finally we plot our filtered data against the profile: + ```{r profile_plot1} -ggplot(quakes_profile_filtered, aes(X/1000, depth, color = depth, size = mag)) + +ggplot(quakes_profile_filtered, aes(X, depth, color = depth, size = mag)) + geom_point() + scale_size_binned("Richter Magnitude") + scale_y_reverse() + @@ -154,9 +188,9 @@ than the more distant points. This gives a somewhat 3-dimensional look to it: ```{r profile_plot2} - quakes_profile |> + quakes_profile_shifted |> arrange(desc(abs(Y))) |> - ggplot(aes(X / 1000, depth, color = mag, size = abs(Y) / 1000, alpha = abs(Y) / 1000)) + + ggplot(aes(X, depth, color = mag, size = abs(Y), alpha = abs(Y))) + geom_point() + scale_color_viridis_c("Richter Magnitude", option = "A") + scale_size_continuous("Distance from profile (km)", range = c(3, .1)) +