diff --git a/NAMESPACE b/NAMESPACE index ca51d28..8337291 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,6 +8,8 @@ export(plot_dz) export(plot_slope) export(route_to_segments) export(sequential_dist) +export(slope_breaks) +export(slope_colors) export(slope_distance) export(slope_distance_mean) export(slope_distance_weighted) diff --git a/R/palette.R b/R/palette.R index bb377e1..a22c26a 100644 --- a/R/palette.R +++ b/R/palette.R @@ -1,5 +1,45 @@ # R/palette.R +#' Recommended slope colours (dark green to dark red) +#' +#' A character vector of twelve hex colours for use with \code{\link{slope_breaks}} +#' and \code{\link{plot_slope}}. Colours run from dark green (flat) through amber +#' to dark red (steep), covering both downhill (negative) and uphill (positive) +#' slope directions — six colours per direction. +#' +#' @format A character vector of length 12. +#' @seealso \code{\link{slope_breaks}}, \code{\link{slopes_palette}} +#' @examples +#' slope_colors +#' \donttest{ +#' route_xyz <- elevation_add(lisbon_route, dem = dem_lisbon()) +#' plot_slope(route_xyz, pal = slope_colors, brks = slope_breaks) +#' } +#' @export +slope_colors <- c( + "#730000", "#A80000", "#E60000", "#FFAA00", "#70A800", "#267300", # downhill + "#267300", "#70A800", "#FFAA00", "#E60000", "#A80000", "#730000" # uphill +) + +#' Recommended slope break thresholds +#' +#' A numeric vector of six positive break points in **percentage units** +#' (e.g. 5 = 5\%), without \code{0} or \code{Inf}. +#' \code{\link{plot_slope}} uses these to build a symmetric set of 12 intervals +#' (downhill and uphill), matched to the 12 colours in \code{\link{slope_colors}}. +#' +#' @format A numeric vector of length 6. +#' @seealso \code{\link{slope_colors}}, \code{\link{slopes_palette}} +#' @examples +#' slope_breaks +#' \donttest{ +#' route_xyz <- elevation_add(lisbon_route, dem = dem_lisbon()) +#' plot_slope(route_xyz, pal = slope_colors, brks = slope_breaks) +#' } +#' @export +slope_breaks <- c(3, 5, 8, 10, 20, 100) + + #' Get color palette for slopes visualization #' #' Returns a color palette suitable for visualizing slope data, with options diff --git a/man/slope_breaks.Rd b/man/slope_breaks.Rd new file mode 100644 index 0000000..12d7ce0 --- /dev/null +++ b/man/slope_breaks.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/palette.R +\name{slope_breaks} +\alias{slope_breaks} +\title{Recommended slope break thresholds} +\format{ +A numeric vector of length 6. +} +\usage{ +slope_breaks +} +\description{ +A numeric vector of six positive break points in \strong{percentage units} +(e.g. 5 = 5\\%), without \code{0} or \code{Inf}. +\code{\link{plot_slope}} uses these to build a symmetric set of 12 intervals +(downhill and uphill), matched to the 12 colours in \code{\link{slope_colors}}. +} +\examples{ +slope_breaks +\donttest{ +route_xyz <- elevation_add(lisbon_route, dem = dem_lisbon()) +plot_slope(route_xyz, pal = slope_colors, brks = slope_breaks) +} +} +\seealso{ +\code{\link{slope_colors}}, \code{\link{slopes_palette}} +} diff --git a/man/slope_colors.Rd b/man/slope_colors.Rd new file mode 100644 index 0000000..8fc5c7e --- /dev/null +++ b/man/slope_colors.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/palette.R +\name{slope_colors} +\alias{slope_colors} +\title{Recommended slope colours (dark green to dark red)} +\format{ +A character vector of length 12. +} +\usage{ +slope_colors +} +\description{ +A character vector of twelve hex colours for use with \code{\link{slope_breaks}} +and \code{\link{plot_slope}}. Colours run from dark green (flat) through amber +to dark red (steep), covering both downhill (negative) and uphill (positive) +slope directions — six colours per direction. +} +\examples{ +slope_colors +\donttest{ +route_xyz <- elevation_add(lisbon_route, dem = dem_lisbon()) +plot_slope(route_xyz, pal = slope_colors, brks = slope_breaks) +} +} +\seealso{ +\code{\link{slope_breaks}}, \code{\link{slopes_palette}} +} diff --git a/vignettes/slopes.Rmd b/vignettes/slopes.Rmd index ec506f5..ab112b7 100644 --- a/vignettes/slopes.Rmd +++ b/vignettes/slopes.Rmd @@ -132,11 +132,9 @@ slope You can visualize the elevation profile of a 3D linestring using `plot_slope()`: ```{r} -# ensure a palette and breaks exist -brks <- c(3, 6, 10, 20, 40, 100) -pal <- slopes_palette(length(brks) - 1) +# Use the recommended green-to-red palette and matching break thresholds -plot_slope(sf_linestring_xyz_local, pal = pal, brks = brks) +plot_slope(sf_linestring_xyz_local, pal = slope_colors, brks = slope_breaks) ``` ## Working with segments @@ -157,7 +155,8 @@ summary(lisbon_route_segments_xyz$slope) ```{r} plot(st_geometry(lisbon_route_segments_xyz), - col = heat.colors(length(lisbon_route_segments_xyz$slope))[rank(lisbon_route_segments_xyz$slope)], + col = slope_colors[7:12][cut(abs(lisbon_route_segments_xyz$slope) * 100, + breaks = slope_breaks, labels = FALSE, include.lowest = TRUE)], lwd = 3, main = "Slope by vertex segments" ) ``` @@ -176,7 +175,8 @@ summary(lisbon_route_100m_xyz$slope) ```{r} plot(st_geometry(lisbon_route_100m_xyz), - col = heat.colors(length(lisbon_route_100m_xyz$slope))[rank(lisbon_route_100m_xyz$slope)], + col = slope_colors[7:12][cut(abs(lisbon_route_100m_xyz$slope) * 100, + breaks = slope_breaks, labels = FALSE, include.lowest = TRUE)], lwd = 3, main = "Slope by 100 m segments" ) ```