Skip to content

Commit

Permalink
Merge branch 'plot' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
loreabad6 committed Apr 6, 2020
2 parents 8bfd77f + dbeef5c commit bc273b1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Imports:
sf,
tidygraph,
utils,
pillar
pillar,
graphics
Suggests:
tidyverse,
knitr,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ S3method(as_sfnetwork,sf)
S3method(as_sfnetwork,tbl_graph)
S3method(as_tbl_graph,sfnetwork)
S3method(as_tibble,sfnetwork)
S3method(plot,sfnetwork)
S3method(print,sfnetwork)
S3method(st_area,sfnetwork)
S3method(st_as_sf,sfnetwork)
Expand Down Expand Up @@ -56,6 +57,7 @@ export(st_overlaps.sfnetwork)
export(st_relate.sfnetwork)
export(st_touches.sfnetwork)
export(st_within.sfnetwork)
importFrom(graphics,plot)
importFrom(igraph,is_directed)
importFrom(pillar,style_subtle)
importFrom(rlang,"!!")
Expand Down
26 changes: 26 additions & 0 deletions R/plot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#' Plot sfnetwork object
#'
#' Plot spatially explicit graph components (nodes and edges) of an sfnetwork on a map
#'
#' @param x object of class sfnetwork
#' @param ... further parameters passed to \code{\link[sf]{plot}}
#' @importFrom graphics plot
#' @export
plot.sfnetwork = function(x, ...){
dots = list(...)

pch_missing = is.null(dots$pch)

sfn = sf::st_geometry(sf::st_as_sf(activate(x, "nodes")))

if (has_spatially_explicit_edges(x)) {
sfe = sf::st_geometry(sf::st_as_sf(activate(x, "edges")))
sfgraph = c(sfn, sfe)
dots$x = sfgraph
} else {
dots$x = sfn
}

dots$pch = if (pch_missing) 20 else dots$pch
do.call(plot, dots)
}
16 changes: 16 additions & 0 deletions man/plot.sfnetwork.Rd

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

0 comments on commit bc273b1

Please sign in to comment.