Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions R/palette.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
27 changes: 27 additions & 0 deletions man/slope_breaks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions man/slope_colors.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions vignettes/slopes.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
)
```
Expand All @@ -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"
)
```
Expand Down
Loading